1
1
import Maybe from '../tsutils/Maybe' ;
2
+ import { PromiseOrValue } from '../jsutils/PromiseOrValue' ;
3
+ import { Path , addPath , pathToArray } from '../jsutils/Path' ;
4
+
2
5
import { GraphQLError , locatedError } from '../error' ;
3
- import { GraphQLSchema } from '../type/schema' ;
4
- import {
5
- GraphQLField ,
6
- GraphQLFieldResolver ,
7
- ResponsePath ,
8
- GraphQLObjectType ,
9
- GraphQLResolveInfo ,
10
- } from '../type/definition' ;
11
6
import {
12
7
DirectiveNode ,
13
8
DocumentNode ,
@@ -17,7 +12,14 @@ import {
17
12
InlineFragmentNode ,
18
13
FragmentDefinitionNode ,
19
14
} from '../language/ast' ;
20
- import { PromiseOrValue } from '../jsutils/PromiseOrValue' ;
15
+ import { GraphQLSchema } from '../type/schema' ;
16
+ import {
17
+ GraphQLField ,
18
+ GraphQLFieldResolver ,
19
+ GraphQLResolveInfo ,
20
+ GraphQLTypeResolver ,
21
+ GraphQLObjectType ,
22
+ } from '../type/definition' ;
21
23
22
24
/**
23
25
* Data that must be available at all points during query execution.
@@ -46,9 +48,10 @@ export interface ExecutionResultDataDefault {
46
48
* - `errors` is included when any errors occurred as a non-empty array.
47
49
* - `data` is the result of a successful execution of the query.
48
50
*/
51
+ // TS_SPECIFIC: TData and ExecutionResultDataDefault
49
52
export interface ExecutionResult < TData = ExecutionResultDataDefault > {
50
53
errors ?: ReadonlyArray < GraphQLError > ;
51
- data ?: TData ;
54
+ data ?: TData | null ;
52
55
}
53
56
54
57
export type ExecutionArgs = {
@@ -59,6 +62,7 @@ export type ExecutionArgs = {
59
62
variableValues ?: Maybe < { [ key : string ] : any } > ;
60
63
operationName ?: Maybe < string > ;
61
64
fieldResolver ?: Maybe < GraphQLFieldResolver < any , any > > ;
65
+ typeResolver ?: Maybe < GraphQLTypeResolver < any , any > > ;
62
66
} ;
63
67
64
68
/**
@@ -84,26 +88,9 @@ export function execute<TData = ExecutionResultDataDefault>(
84
88
variableValues ?: Maybe < { [ key : string ] : any } > ,
85
89
operationName ?: Maybe < string > ,
86
90
fieldResolver ?: Maybe < GraphQLFieldResolver < any , any > > ,
91
+ typeResolver ?: Maybe < GraphQLTypeResolver < any , any > > ,
87
92
) : PromiseOrValue < ExecutionResult < TData > > ;
88
93
89
- /**
90
- * Given a ResponsePath (found in the `path` entry in the information provided
91
- * as the last argument to a field resolver), return an Array of the path keys.
92
- */
93
- export function responsePathAsArray (
94
- path : ResponsePath ,
95
- ) : ReadonlyArray < string | number > ;
96
-
97
- /**
98
- * Given a ResponsePath and a key, return a new ResponsePath containing the
99
- * new key.
100
-
101
- */
102
- export function addPath (
103
- prev : ResponsePath | undefined ,
104
- key : string | number ,
105
- ) : { prev : ResponsePath | undefined ; key : string | number } ;
106
-
107
94
/**
108
95
* Essential assertions before executing to provide developer feedback for
109
96
* improper use of the GraphQL library.
@@ -128,6 +115,7 @@ export function buildExecutionContext(
128
115
rawVariableValues : Maybe < { [ key : string ] : any } > ,
129
116
operationName : Maybe < string > ,
130
117
fieldResolver : Maybe < GraphQLFieldResolver < any , any > > ,
118
+ typeResolver ?: Maybe < GraphQLTypeResolver < any , any > > ,
131
119
) : ReadonlyArray < GraphQLError > | ExecutionContext ;
132
120
133
121
/**
@@ -151,11 +139,12 @@ export function buildResolveInfo(
151
139
fieldDef : GraphQLField < any , any > ,
152
140
fieldNodes : ReadonlyArray < FieldNode > ,
153
141
parentType : GraphQLObjectType ,
154
- path : ResponsePath ,
142
+ path : Path ,
155
143
) : GraphQLResolveInfo ;
156
144
157
145
// Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
158
146
// function. Returns the result of resolveFn or the abrupt-return Error object.
147
+ // TS_SPECIFIC: TSource
159
148
export function resolveFieldValueOrError < TSource > (
160
149
exeContext : ExecutionContext ,
161
150
fieldDef : GraphQLField < TSource , any > ,
@@ -165,6 +154,18 @@ export function resolveFieldValueOrError<TSource>(
165
154
info : GraphQLResolveInfo ,
166
155
) : Error | any ;
167
156
157
+ /**
158
+ * If a resolveType function is not given, then a default resolve behavior is
159
+ * used which attempts two strategies:
160
+ *
161
+ * First, See if the provided value has a `__typename` field defined, if so, use
162
+ * that value as name of the resolved type.
163
+ *
164
+ * Otherwise, test each possible type for the abstract type by calling
165
+ * isTypeOf for the object being coerced, returning the first type that matches.
166
+ */
167
+ export const defaultTypeResolver : GraphQLTypeResolver < any , any > ;
168
+
168
169
/**
169
170
* If a resolve function is not given, then a default resolve behavior is used
170
171
* which takes the property of the source object of the same name as the field
0 commit comments