Skip to content

Commit 494a3d2

Browse files
Synchronise TS typings for graphql.js/execute.js/subscribe.js (#2987)
Removal of positional args was done in #2904 but TS typings were not updated.
1 parent 32a053b commit 494a3d2

File tree

3 files changed

+61
-57
lines changed

3 files changed

+61
-57
lines changed

src/execution/execute.d.ts

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ import {
2222
GraphQLObjectType,
2323
} from '../type/definition';
2424

25+
/**
26+
* Terminology
27+
*
28+
* "Definitions" are the generic name for top-level statements in the document.
29+
* Examples of this include:
30+
* 1) Operations (such as a query)
31+
* 2) Fragments
32+
*
33+
* "Operations" are a generic name for requests in the document.
34+
* Examples of this include:
35+
* 1) query,
36+
* 2) mutation
37+
*
38+
* "Selections" are the definitions that can appear legally and at
39+
* single level of the query. These include:
40+
* 1) field references e.g "a"
41+
* 2) fragment "spreads" e.g. "...c"
42+
* 3) inline fragment "spreads" e.g. "...on Type { a }"
43+
*/
44+
2545
/**
2646
* Data that must be available at all points during query execution.
2747
*
@@ -36,6 +56,7 @@ export interface ExecutionContext {
3656
operation: OperationDefinitionNode;
3757
variableValues: { [key: string]: any };
3858
fieldResolver: GraphQLFieldResolver<any, any>;
59+
typeResolver: GraphQLTypeResolver<any, any>;
3960
errors: Array<GraphQLError>;
4061
}
4162

@@ -86,20 +107,8 @@ export interface ExecutionArgs {
86107
*
87108
* If the arguments to this function do not result in a legal execution context,
88109
* a GraphQLError will be thrown immediately explaining the invalid input.
89-
*
90-
* Accepts either an object with named arguments, or individual arguments.
91110
*/
92111
export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult>;
93-
export function execute(
94-
schema: GraphQLSchema,
95-
document: DocumentNode,
96-
rootValue?: any,
97-
contextValue?: any,
98-
variableValues?: Maybe<{ [key: string]: any }>,
99-
operationName?: Maybe<string>,
100-
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
101-
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
102-
): PromiseOrValue<ExecutionResult>;
103112

104113
/**
105114
* Also implements the "Evaluating requests" section of the GraphQL specification.
@@ -111,6 +120,8 @@ export function executeSync(args: ExecutionArgs): ExecutionResult;
111120
/**
112121
* Essential assertions before executing to provide developer feedback for
113122
* improper use of the GraphQL library.
123+
*
124+
* @internal
114125
*/
115126
export function assertValidExecutionArguments(
116127
schema: GraphQLSchema,
@@ -123,6 +134,8 @@ export function assertValidExecutionArguments(
123134
* execute, which we will pass throughout the other execution methods.
124135
*
125136
* Throws a GraphQLError if a valid execution context cannot be created.
137+
*
138+
* @internal
126139
*/
127140
export function buildExecutionContext(
128141
schema: GraphQLSchema,
@@ -142,6 +155,8 @@ export function buildExecutionContext(
142155
* CollectFields requires the "runtime type" of an object. For a field which
143156
* returns an Interface or Union type, the "runtime type" will be the actual
144157
* Object type returned by that field.
158+
*
159+
* @internal
145160
*/
146161
export function collectFields(
147162
exeContext: ExecutionContext,
@@ -151,6 +166,9 @@ export function collectFields(
151166
visitedFragmentNames: { [key: string]: boolean },
152167
): { [key: string]: Array<FieldNode> };
153168

169+
/**
170+
* @internal
171+
*/
154172
export function buildResolveInfo(
155173
exeContext: ExecutionContext,
156174
fieldDef: GraphQLField<any, any>,
@@ -175,18 +193,20 @@ export const defaultTypeResolver: GraphQLTypeResolver<any, any>;
175193
* If a resolve function is not given, then a default resolve behavior is used
176194
* which takes the property of the source object of the same name as the field
177195
* and returns it as the result, or if it's a function, returns the result
178-
* of calling that function while passing along args and context.
196+
* of calling that function while passing along args and context value.
179197
*/
180198
export const defaultFieldResolver: GraphQLFieldResolver<any, any>;
181199

182200
/**
183201
* This method looks up the field on the given type definition.
184-
* It has special casing for the two introspection fields, __schema
185-
* and __typename. __typename is special because it can always be
186-
* queried as a field, even in situations where no other fields
187-
* are allowed, like on a Union. __schema could get automatically
188-
* added to the query type, but that would require mutating type
189-
* definitions, which would cause issues.
202+
* It has special casing for the three introspection fields,
203+
* __schema, __type and __typename. __typename is special because
204+
* it can always be queried as a field, even in situations where no
205+
* other fields are allowed, like on a Union. __schema and __type
206+
* could get automatically added to the query type, but that would
207+
* require mutating type definitions, which would cause issues.
208+
*
209+
* @internal
190210
*/
191211
export function getFieldDef(
192212
schema: GraphQLSchema,

src/graphql.d.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ import { ExecutionResult } from './execution/execute';
3939
* A resolver function to use when one is not provided by the schema.
4040
* If not provided, the default field resolver is used (which looks for a
4141
* value or method on the source value with the field's name).
42+
* typeResolver:
43+
* A type resolver function to use when none is provided by the schema.
44+
* If not provided, the default type resolver is used (which looks for a
45+
* `__typename` field or alternatively calls the `isTypeOf` method).
4246
*/
4347
export interface GraphQLArgs {
4448
schema: GraphQLSchema;
@@ -52,16 +56,6 @@ export interface GraphQLArgs {
5256
}
5357

5458
export function graphql(args: GraphQLArgs): Promise<ExecutionResult>;
55-
export function graphql(
56-
schema: GraphQLSchema,
57-
source: Source | string,
58-
rootValue?: any,
59-
contextValue?: any,
60-
variableValues?: Maybe<{ [key: string]: any }>,
61-
operationName?: Maybe<string>,
62-
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
63-
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
64-
): Promise<ExecutionResult>;
6559

6660
/**
6761
* The graphqlSync function also fulfills GraphQL operations by parsing,
@@ -70,13 +64,3 @@ export function graphql(
7064
* that all field resolvers are also synchronous.
7165
*/
7266
export function graphqlSync(args: GraphQLArgs): ExecutionResult;
73-
export function graphqlSync(
74-
schema: GraphQLSchema,
75-
source: Source | string,
76-
rootValue?: any,
77-
contextValue?: any,
78-
variableValues?: Maybe<{ [key: string]: any }>,
79-
operationName?: Maybe<string>,
80-
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
81-
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
82-
): ExecutionResult;

src/subscription/subscribe.d.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ export interface SubscriptionArgs {
2020
* Implements the "Subscribe" algorithm described in the GraphQL specification.
2121
*
2222
* Returns a Promise which resolves to either an AsyncIterator (if successful)
23-
* or an ExecutionResult (client error). The promise will be rejected if a
24-
* server error occurs.
23+
* or an ExecutionResult (error). The promise will be rejected if the schema or
24+
* other arguments to this function are invalid, or if the resolved event stream
25+
* is not an async iterable.
2526
*
2627
* If the client-provided arguments to this function do not result in a
2728
* compliant subscription, a GraphQL Response (ExecutionResult) with
2829
* descriptive errors and no data will be returned.
2930
*
30-
* If the the source stream could not be created due to faulty subscription
31+
* If the source stream could not be created due to faulty subscription
3132
* resolver logic or underlying systems, the promise will resolve to a single
3233
* ExecutionResult containing `errors` and no `data`.
3334
*
@@ -40,26 +41,25 @@ export function subscribe(
4041
args: SubscriptionArgs,
4142
): Promise<AsyncIterableIterator<ExecutionResult> | ExecutionResult>;
4243

43-
export function subscribe(
44-
schema: GraphQLSchema,
45-
document: DocumentNode,
46-
rootValue?: any,
47-
contextValue?: any,
48-
variableValues?: Maybe<{ [key: string]: any }>,
49-
operationName?: Maybe<string>,
50-
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
51-
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
52-
): Promise<AsyncIterableIterator<ExecutionResult> | ExecutionResult>;
53-
5444
/**
5545
* Implements the "CreateSourceEventStream" algorithm described in the
5646
* GraphQL specification, resolving the subscription source event stream.
5747
*
58-
* Returns a Promise<AsyncIterable>.
48+
* Returns a Promise which resolves to either an AsyncIterable (if successful)
49+
* or an ExecutionResult (error). The promise will be rejected if the schema or
50+
* other arguments to this function are invalid, or if the resolved event stream
51+
* is not an async iterable.
52+
*
53+
* If the client-provided arguments to this function do not result in a
54+
* compliant subscription, a GraphQL Response (ExecutionResult) with
55+
* descriptive errors and no data will be returned.
56+
*
57+
* If the the source stream could not be created due to faulty subscription
58+
* resolver logic or underlying systems, the promise will resolve to a single
59+
* ExecutionResult containing `errors` and no `data`.
5960
*
60-
* If the client-provided invalid arguments, the source stream could not be
61-
* created, or the resolver did not return an AsyncIterable, this function will
62-
* will throw an error, which should be caught and handled by the caller.
61+
* If the operation succeeded, the promise resolves to the AsyncIterable for the
62+
* event stream returned by the resolver.
6363
*
6464
* A Source Event Stream represents a sequence of events, each of which triggers
6565
* a GraphQL execution for that event.

0 commit comments

Comments
 (0)