Skip to content

Commit 544fe7b

Browse files
Synchronise *.d.ts with sources converted to TS (#3132)
1 parent 5e062ea commit 544fe7b

Some content is hidden

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

58 files changed

+671
-472
lines changed

src/error/GraphQLError.d.ts

+26-16
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ import type { SourceLocation } from '../language/location';
99
* GraphQL document and/or execution result that correspond to the Error.
1010
*/
1111
export class GraphQLError extends Error {
12-
constructor(
13-
message: string,
14-
nodes?: Maybe<ReadonlyArray<ASTNode> | ASTNode>,
15-
source?: Maybe<Source>,
16-
positions?: Maybe<ReadonlyArray<number>>,
17-
path?: Maybe<ReadonlyArray<string | number>>,
18-
originalError?: Maybe<Error>,
19-
extensions?: Maybe<{ [key: string]: unknown }>,
20-
);
2112
/**
2213
* A message describing the Error for debugging purposes.
2314
*
@@ -36,38 +27,57 @@ export class GraphQLError extends Error {
3627
*
3728
* Enumerable, and appears in the result of JSON.stringify().
3829
*/
39-
readonly locations: ReadonlyArray<SourceLocation> | undefined;
30+
readonly locations?: ReadonlyArray<SourceLocation>;
4031
/**
4132
* An array describing the JSON-path into the execution response which
4233
* corresponds to this error. Only included for errors during execution.
4334
*
4435
* Enumerable, and appears in the result of JSON.stringify().
4536
*/
46-
readonly path: ReadonlyArray<string | number> | undefined;
37+
readonly path?: ReadonlyArray<string | number>;
4738
/**
4839
* An array of GraphQL AST Nodes corresponding to this error.
4940
*/
50-
readonly nodes: ReadonlyArray<ASTNode> | undefined;
41+
readonly nodes?: ReadonlyArray<ASTNode>;
5142
/**
52-
* The source GraphQL document corresponding to this error.
43+
* The source GraphQL document for the first location of this error.
5344
*
5445
* Note that if this Error represents more than one node, the source may not
5546
* represent nodes after the first node.
5647
*/
57-
readonly source: Source | undefined;
48+
readonly source?: Source;
5849
/**
5950
* An array of character offsets within the source GraphQL document
6051
* which correspond to this error.
6152
*/
62-
readonly positions: ReadonlyArray<number> | undefined;
53+
readonly positions?: ReadonlyArray<number>;
6354
/**
6455
* The original error thrown from a field resolver during execution.
6556
*/
6657
readonly originalError: Maybe<Error>;
6758
/**
6859
* Extension fields to add to the formatted error.
6960
*/
70-
readonly extensions: { [key: string]: unknown } | undefined;
61+
readonly extensions?: {
62+
[key: string]: unknown;
63+
};
64+
constructor(
65+
message: string,
66+
nodes?: ReadonlyArray<ASTNode> | ASTNode | null,
67+
source?: Maybe<Source>,
68+
positions?: Maybe<ReadonlyArray<number>>,
69+
path?: Maybe<ReadonlyArray<string | number>>,
70+
originalError?: Maybe<
71+
Error & {
72+
readonly extensions?: unknown;
73+
}
74+
>,
75+
extensions?: Maybe<{
76+
[key: string]: unknown;
77+
}>,
78+
);
79+
toString(): string;
80+
get [Symbol.toStringTag](): string;
7181
}
7282
/**
7383
* Prints a GraphQLError to a string, representing useful location information

src/error/formatError.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ export interface GraphQLFormattedError {
3131
* Reserved for implementors to extend the protocol however they see fit,
3232
* and hence there are no additional restrictions on its contents.
3333
*/
34-
readonly extensions?: { [key: string]: unknown };
34+
readonly extensions?: {
35+
[key: string]: unknown;
36+
};
3537
}

src/error/index.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { GraphQLError, printError } from './GraphQLError';
22
export { syntaxError } from './syntaxError';
33
export { locatedError } from './locatedError';
4-
export { formatError, GraphQLFormattedError } from './formatError';
4+
export { formatError } from './formatError';
5+
export type { GraphQLFormattedError } from './formatError';

src/error/locatedError.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { Maybe } from '../jsutils/Maybe';
22
import type { ASTNode } from '../language/ast';
3-
import type { GraphQLError } from './GraphQLError';
3+
import { GraphQLError } from './GraphQLError';
44
/**
55
* Given an arbitrary value, presumably thrown while attempting to execute a
66
* GraphQL operation, produce a new GraphQLError aware of the location in the
77
* document responsible for the original Error.
88
*/
99
export function locatedError(
1010
rawOriginalError: unknown,
11-
nodes: ASTNode | ReadonlyArray<ASTNode> | undefined,
11+
nodes: ASTNode | ReadonlyArray<ASTNode> | undefined | null,
1212
path?: Maybe<ReadonlyArray<string | number>>,
1313
): GraphQLError;

src/error/syntaxError.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Source } from '../language/source';
2-
import type { GraphQLError } from './GraphQLError';
2+
import { GraphQLError } from './GraphQLError';
33
/**
44
* Produces a GraphQLError representing a syntax error, containing useful
55
* descriptive information about the syntax error's position in the source.

src/execution/execute.d.ts

+25-19
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { Maybe } from '../jsutils/Maybe';
1+
import type { Path } from '../jsutils/Path';
22
import type { ObjMap } from '../jsutils/ObjMap';
33
import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
4-
import type { Path } from '../jsutils/Path';
5-
import type { GraphQLError } from '../error/GraphQLError';
4+
import type { Maybe } from '../jsutils/Maybe';
65
import type { GraphQLFormattedError } from '../error/formatError';
6+
import { GraphQLError } from '../error/GraphQLError';
77
import type {
88
DocumentNode,
99
OperationDefinitionNode,
@@ -13,11 +13,11 @@ import type {
1313
} from '../language/ast';
1414
import type { GraphQLSchema } from '../type/schema';
1515
import type {
16+
GraphQLObjectType,
1617
GraphQLField,
1718
GraphQLFieldResolver,
1819
GraphQLResolveInfo,
1920
GraphQLTypeResolver,
20-
GraphQLObjectType,
2121
} from '../type/definition';
2222
/**
2323
* Terminology
@@ -46,11 +46,13 @@ import type {
4646
*/
4747
export interface ExecutionContext {
4848
schema: GraphQLSchema;
49+
fragments: ObjMap<FragmentDefinitionNode>;
4950
rootValue: unknown;
5051
contextValue: unknown;
51-
fragments: ObjMap<FragmentDefinitionNode>;
5252
operation: OperationDefinitionNode;
53-
variableValues: { [key: string]: unknown };
53+
variableValues: {
54+
[variable: string]: unknown;
55+
};
5456
fieldResolver: GraphQLFieldResolver<any, any>;
5557
typeResolver: GraphQLTypeResolver<any, any>;
5658
errors: Array<GraphQLError>;
@@ -63,20 +65,18 @@ export interface ExecutionContext {
6365
* - `extensions` is reserved for adding non-standard properties.
6466
*/
6567
export interface ExecutionResult<
66-
TData = { [key: string]: any },
67-
TExtensions = { [key: string]: any },
68+
TData = ObjMap<unknown>,
69+
TExtensions = ObjMap<unknown>,
6870
> {
6971
errors?: ReadonlyArray<GraphQLError>;
70-
// TS_SPECIFIC: TData. Motivation: https://github.com/graphql/graphql-js/pull/2490#issuecomment-639154229
7172
data?: TData | null;
7273
extensions?: TExtensions;
7374
}
7475
export interface FormattedExecutionResult<
75-
TData = { [key: string]: any },
76-
TExtensions = { [key: string]: any },
76+
TData = ObjMap<unknown>,
77+
TExtensions = ObjMap<unknown>,
7778
> {
7879
errors?: ReadonlyArray<GraphQLFormattedError>;
79-
// TS_SPECIFIC: TData. Motivation: https://github.com/graphql/graphql-js/pull/2490#issuecomment-639154229
8080
data?: TData | null;
8181
extensions?: TExtensions;
8282
}
@@ -85,7 +85,9 @@ export interface ExecutionArgs {
8585
document: DocumentNode;
8686
rootValue?: unknown;
8787
contextValue?: unknown;
88-
variableValues?: Maybe<{ [key: string]: unknown }>;
88+
variableValues?: Maybe<{
89+
readonly [variable: string]: unknown;
90+
}>;
8991
operationName?: Maybe<string>;
9092
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
9193
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
@@ -116,7 +118,9 @@ export function executeSync(args: ExecutionArgs): ExecutionResult;
116118
export function assertValidExecutionArguments(
117119
schema: GraphQLSchema,
118120
document: DocumentNode,
119-
rawVariableValues: Maybe<{ [key: string]: unknown }>,
121+
rawVariableValues: Maybe<{
122+
readonly [variable: string]: unknown;
123+
}>,
120124
): void;
121125
/**
122126
* Constructs a ExecutionContext object from the arguments passed to
@@ -131,7 +135,9 @@ export function buildExecutionContext(
131135
document: DocumentNode,
132136
rootValue: unknown,
133137
contextValue: unknown,
134-
rawVariableValues: Maybe<{ [key: string]: unknown }>,
138+
rawVariableValues: Maybe<{
139+
readonly [variable: string]: unknown;
140+
}>,
135141
operationName: Maybe<string>,
136142
fieldResolver: Maybe<GraphQLFieldResolver<unknown, unknown>>,
137143
typeResolver?: Maybe<GraphQLTypeResolver<unknown, unknown>>,
@@ -150,9 +156,9 @@ export function collectFields(
150156
exeContext: ExecutionContext,
151157
runtimeType: GraphQLObjectType,
152158
selectionSet: SelectionSetNode,
153-
fields: ObjMap<Array<FieldNode>>,
154-
visitedFragmentNames: ObjMap<boolean>,
155-
): ObjMap<Array<FieldNode>>;
159+
fields: Map<string, Array<FieldNode>>,
160+
visitedFragmentNames: Set<string>,
161+
): Map<string, Array<FieldNode>>;
156162
/**
157163
* @internal
158164
*/
@@ -195,5 +201,5 @@ export const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown>;
195201
export function getFieldDef(
196202
schema: GraphQLSchema,
197203
parentType: GraphQLObjectType,
198-
fieldName: string,
204+
fieldNode: FieldNode,
199205
): Maybe<GraphQLField<unknown, unknown>>;

src/execution/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export {
44
executeSync,
55
defaultFieldResolver,
66
defaultTypeResolver,
7+
} from './execute';
8+
export type {
79
ExecutionArgs,
810
ExecutionResult,
911
FormattedExecutionResult,

src/execution/values.d.ts

+31-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
import type { Maybe } from '../jsutils/Maybe';
21
import type { ObjMap } from '../jsutils/ObjMap';
3-
import type { GraphQLError } from '../error/GraphQLError';
2+
import type { Maybe } from '../jsutils/Maybe';
3+
import { GraphQLError } from '../error/GraphQLError';
44
import type {
55
FieldNode,
66
DirectiveNode,
77
VariableDefinitionNode,
88
} from '../language/ast';
9-
import type { GraphQLDirective } from '../type/directives';
109
import type { GraphQLSchema } from '../type/schema';
1110
import type { GraphQLField } from '../type/definition';
11+
import type { GraphQLDirective } from '../type/directives';
1212
type CoercedVariableValues =
13-
| { errors: ReadonlyArray<GraphQLError>; coerced?: never }
14-
| { errors?: never; coerced: { [key: string]: unknown } };
13+
| {
14+
errors: ReadonlyArray<GraphQLError>;
15+
coerced?: never;
16+
}
17+
| {
18+
coerced: {
19+
[variable: string]: unknown;
20+
};
21+
errors?: never;
22+
};
1523
/**
1624
* Prepares an object map of variableValues of the correct type based on the
1725
* provided variable definitions and arbitrary input. If the input cannot be
@@ -20,12 +28,18 @@ type CoercedVariableValues =
2028
* Note: The returned value is a plain Object with a prototype, since it is
2129
* exposed to user code. Care should be taken to not pull values from the
2230
* Object prototype.
31+
*
32+
* @internal
2333
*/
2434
export function getVariableValues(
2535
schema: GraphQLSchema,
2636
varDefNodes: ReadonlyArray<VariableDefinitionNode>,
27-
inputs: { [key: string]: unknown },
28-
options?: { maxErrors?: number },
37+
inputs: {
38+
readonly [variable: string]: unknown;
39+
},
40+
options?: {
41+
maxErrors?: number;
42+
},
2943
): CoercedVariableValues;
3044
/**
3145
* Prepares an object map of argument values given a list of argument
@@ -34,12 +48,16 @@ export function getVariableValues(
3448
* Note: The returned value is a plain Object with a prototype, since it is
3549
* exposed to user code. Care should be taken to not pull values from the
3650
* Object prototype.
51+
*
52+
* @internal
3753
*/
3854
export function getArgumentValues(
3955
def: GraphQLField<unknown, unknown> | GraphQLDirective,
4056
node: FieldNode | DirectiveNode,
4157
variableValues?: Maybe<ObjMap<unknown>>,
42-
): { [key: string]: unknown };
58+
): {
59+
[argument: string]: unknown;
60+
};
4361
/**
4462
* Prepares an object map of argument values given a directive definition
4563
* and a AST node which may contain directives. Optionally also accepts a map
@@ -57,4 +75,8 @@ export function getDirectiveValues(
5775
readonly directives?: ReadonlyArray<DirectiveNode>;
5876
},
5977
variableValues?: Maybe<ObjMap<unknown>>,
60-
): undefined | { [key: string]: unknown };
78+
):
79+
| undefined
80+
| {
81+
[argument: string]: unknown;
82+
};

src/graphql.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { Maybe } from './jsutils/Maybe';
22
import type { Source } from './language/source';
3-
import type { GraphQLSchema } from './type/schema';
43
import type {
54
GraphQLFieldResolver,
65
GraphQLTypeResolver,
76
} from './type/definition';
7+
import type { GraphQLSchema } from './type/schema';
88
import type { ExecutionResult } from './execution/execute';
99
/**
1010
* This is the primary entry point function for fulfilling GraphQL operations
@@ -50,7 +50,9 @@ export interface GraphQLArgs {
5050
source: string | Source;
5151
rootValue?: unknown;
5252
contextValue?: unknown;
53-
variableValues?: Maybe<{ [key: string]: unknown }>;
53+
variableValues?: Maybe<{
54+
readonly [variable: string]: unknown;
55+
}>;
5456
operationName?: Maybe<string>;
5557
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
5658
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;

0 commit comments

Comments
 (0)