Skip to content

Commit 19abf40

Browse files
saihajIvanGoncharov
authored andcommitted
Switch to TS syntax (#3090)
1 parent fee4bb4 commit 19abf40

File tree

97 files changed

+1191
-1144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1191
-1144
lines changed

old_dts/utilities/astFromValue.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { GraphQLInputType } from '../type/definition';
1616
* | Boolean | Boolean |
1717
* | String | String / Enum Value |
1818
* | Number | Int / Float |
19-
* | Mixed | Enum Value |
19+
* | Unknown | Enum Value |
2020
* | null | NullValue |
2121
*
2222
*/

old_dts/utilities/valueFromAST.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { GraphQLInputType } from '../type/definition';
2020
* | Boolean | Boolean |
2121
* | String | String |
2222
* | Int / Float | Number |
23-
* | Enum Value | Mixed |
23+
* | Enum Value | Unknown |
2424
* | NullValue | null |
2525
*
2626
*/

src/__testUtils__/dedent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export function dedentString(string: string): string {
2727
* str === "{\n test\n}";
2828
*/
2929
export function dedent(
30-
strings: $ReadOnlyArray<string>,
31-
...values: $ReadOnlyArray<string>
30+
strings: ReadonlyArray<string>,
31+
...values: ReadonlyArray<string>
3232
): string {
3333
let str = strings[0];
3434

src/__testUtils__/inspectStr.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import type { Maybe } from '../jsutils/Maybe';
2+
13
/**
24
* Special inspect function to produce readable string literal for error messages in tests
35
*/
4-
export function inspectStr(str: ?string): string {
6+
export function inspectStr(str: Maybe<string>): string {
57
if (str == null) {
68
return 'null';
79
}

src/__tests__/starWarsData.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export type Character = {
77
name: string;
88
friends: Array<string>;
99
appearsIn: Array<number>;
10-
...
1110
};
1211

1312
export type Human = {

src/error/GraphQLError.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// flowlint uninitialized-instance-property:off
33

44
import { isObjectLike } from '../jsutils/isObjectLike';
5+
import type { Maybe } from '../jsutils/Maybe';
56

67
import type { ASTNode } from '../language/ast';
78
import type { Source } from '../language/source';
@@ -35,53 +36,53 @@ export class GraphQLError extends Error {
3536
*
3637
* Enumerable, and appears in the result of JSON.stringify().
3738
*/
38-
+locations: $ReadOnlyArray<SourceLocation> | void;
39+
readonly locations: ReadonlyArray<SourceLocation> | void;
3940

4041
/**
4142
* An array describing the JSON-path into the execution response which
4243
* corresponds to this error. Only included for errors during execution.
4344
*
4445
* Enumerable, and appears in the result of JSON.stringify().
4546
*/
46-
+path: $ReadOnlyArray<string | number> | void;
47+
readonly path: ReadonlyArray<string | number> | void;
4748

4849
/**
4950
* An array of GraphQL AST Nodes corresponding to this error.
5051
*/
51-
+nodes: $ReadOnlyArray<ASTNode> | void;
52+
readonly nodes: ReadonlyArray<ASTNode> | void;
5253

5354
/**
5455
* The source GraphQL document for the first location of this error.
5556
*
5657
* Note that if this Error represents more than one node, the source may not
5758
* represent nodes after the first node.
5859
*/
59-
+source: Source | void;
60+
readonly source: Source | void;
6061

6162
/**
6263
* An array of character offsets within the source GraphQL document
6364
* which correspond to this error.
6465
*/
65-
+positions: $ReadOnlyArray<number> | void;
66+
readonly positions: ReadonlyArray<number> | void;
6667

6768
/**
6869
* The original error thrown from a field resolver during execution.
6970
*/
70-
+originalError: ?Error;
71+
readonly originalError: Maybe<Error>;
7172

7273
/**
7374
* Extension fields to add to the formatted error.
7475
*/
75-
+extensions: { [key: string]: mixed; ... } | void;
76+
readonly extensions: { [key: string]: unknown } | void;
7677

7778
constructor(
7879
message: string,
79-
nodes?: $ReadOnlyArray<ASTNode> | ASTNode | void | null,
80-
source?: ?Source,
81-
positions?: ?$ReadOnlyArray<number>,
82-
path?: ?$ReadOnlyArray<string | number>,
83-
originalError?: ?(Error & { +extensions?: mixed; ... }),
84-
extensions?: ?{ [key: string]: mixed; ... },
80+
nodes?: ReadonlyArray<ASTNode> | ASTNode | void | null,
81+
source?: Maybe<Source>,
82+
positions?: Maybe<ReadonlyArray<number>>,
83+
path?: Maybe<ReadonlyArray<string | number>>,
84+
originalError?: Maybe<Error & { readonly extensions?: unknown }>,
85+
extensions?: Maybe<{ [key: string]: unknown }>,
8586
) {
8687
super(message);
8788

src/error/formatError.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ export type GraphQLFormattedError = {
2929
* from occurrence to occurrence of the problem, except for purposes of
3030
* localization.
3131
*/
32-
+message: string;
32+
readonly message: string;
3333
/**
3434
* If an error can be associated to a particular point in the requested
3535
* GraphQL document, it should contain a list of locations.
3636
*/
37-
+locations: $ReadOnlyArray<SourceLocation> | void;
37+
readonly locations: ReadonlyArray<SourceLocation> | void;
3838
/**
3939
* If an error can be associated to a particular field in the GraphQL result,
4040
* it _must_ contain an entry with the key `path` that details the path of
4141
* the response field which experienced the error. This allows clients to
4242
* identify whether a null result is intentional or caused by a runtime error.
4343
*/
44-
+path: $ReadOnlyArray<string | number> | void;
44+
readonly path: ReadonlyArray<string | number> | void;
4545
/**
4646
* Reserved for implementors to extend the protocol however they see fit,
4747
* and hence there are no additional restrictions on its contents.
4848
*/
49-
+extensions?: { [key: string]: mixed; ... };
49+
readonly extensions?: { [key: string]: unknown };
5050
};

src/error/locatedError.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { inspect } from '../jsutils/inspect';
2+
import type { Maybe } from '../jsutils/Maybe';
23

34
import type { ASTNode } from '../language/ast';
45

@@ -10,9 +11,9 @@ import { GraphQLError } from './GraphQLError';
1011
* document responsible for the original Error.
1112
*/
1213
export function locatedError(
13-
rawOriginalError: mixed,
14-
nodes: ASTNode | $ReadOnlyArray<ASTNode> | void | null,
15-
path?: ?$ReadOnlyArray<string | number>,
14+
rawOriginalError: unknown,
15+
nodes: ASTNode | ReadonlyArray<ASTNode> | void | null,
16+
path?: Maybe<ReadonlyArray<string | number>>,
1617
): GraphQLError {
1718
// Sometimes a non-error is thrown, wrap it as an Error instance to ensure a consistent Error interface.
1819
const originalError: Error | GraphQLError =

src/execution/__tests__/abstract-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { executeSync, execute } from '../execute';
2020
async function executeQuery(args: {
2121
schema: GraphQLSchema;
2222
query: string;
23-
rootValue?: mixed;
23+
rootValue?: unknown;
2424
}) {
2525
const { schema, query, rootValue } = args;
2626
const document = parse(query);
@@ -534,7 +534,7 @@ describe('Execute: Handles execution of abstract types', () => {
534534
}
535535
`);
536536

537-
function expectError({ forTypeName }: { forTypeName: mixed }) {
537+
function expectError({ forTypeName }: { forTypeName: unknown }) {
538538
const rootValue = { pet: { __typename: forTypeName } };
539539
const result = executeSync({ schema, document, rootValue });
540540
return {

src/execution/__tests__/lists-test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { buildSchema } from '../../utilities/buildASTSchema';
88
import { execute, executeSync } from '../execute';
99

1010
describe('Execute: Accepts any iterable as list value', () => {
11-
function complete(rootValue: mixed) {
11+
function complete(rootValue: unknown) {
1212
return executeSync({
1313
schema: buildSchema('type Query { listField: [String] }'),
1414
document: parse('{ listField }'),
@@ -65,7 +65,7 @@ describe('Execute: Accepts any iterable as list value', () => {
6565
});
6666

6767
describe('Execute: Handles list nullability', () => {
68-
async function complete(args: { listField: mixed; as: string }) {
68+
async function complete(args: { listField: unknown; as: string }) {
6969
const { listField, as } = args;
7070
const schema = buildSchema(`type Query { listField: ${as} }`);
7171
const document = parse('{ listField }');
@@ -85,11 +85,11 @@ describe('Execute: Handles list nullability', () => {
8585
}
8686
return result;
8787

88-
function executeQuery(listValue: mixed) {
88+
function executeQuery(listValue: unknown) {
8989
return execute({ schema, document, rootValue: { listField: listValue } });
9090
}
9191

92-
function promisify(value: mixed): Promise<mixed> {
92+
function promisify(value: unknown): Promise<unknown> {
9393
return value instanceof Error
9494
? Promise.reject(value)
9595
: Promise.resolve(value);

src/execution/__tests__/nonnull-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const schema = buildSchema(`
106106

107107
function executeQuery(
108108
query: string,
109-
rootValue: mixed,
109+
rootValue: unknown,
110110
): ExecutionResult | Promise<ExecutionResult> {
111111
return execute({ schema, document: parse(query), rootValue });
112112
}
@@ -122,7 +122,7 @@ function patchData(data: ExecutionResult): ExecutionResult {
122122
return JSON.parse(patch(JSON.stringify(data)));
123123
}
124124

125-
async function executeSyncAndAsync(query: string, rootValue: mixed) {
125+
async function executeSyncAndAsync(query: string, rootValue: unknown) {
126126
const syncResult = executeSync({ schema, document: parse(query), rootValue });
127127
const asyncResult = await execute({
128128
schema,

src/execution/__tests__/resolve-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('Execute: resolve function', () => {
9595
resolve: (source, args) => JSON.stringify([source, args]),
9696
});
9797

98-
function executeQuery(query: string, rootValue?: mixed) {
98+
function executeQuery(query: string, rootValue?: unknown) {
9999
const document = parse(query);
100100
return executeSync({ schema, document, rootValue });
101101
}

src/execution/__tests__/variables-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const schema = new GraphQLSchema({ query: TestType });
119119

120120
function executeQuery(
121121
query: string,
122-
variableValues?: { [variable: string]: mixed; ... },
122+
variableValues?: { [variable: string]: unknown },
123123
) {
124124
const document = parse(query);
125125
return executeSync({ schema, document, variableValues });

0 commit comments

Comments
 (0)