@@ -99,28 +99,26 @@ export function resolveSchemaCoordinate(
99
99
}
100
100
101
101
/**
102
- * SchemaCoordinate : Name
102
+ * TypeCoordinate : Name
103
103
*/
104
104
function resolveTypeCoordinate (
105
105
schema : GraphQLSchema ,
106
106
schemaCoordinate : TypeCoordinateNode ,
107
107
) : ResolvedNamedType | undefined {
108
- // 1. Let {typeName} be the value of the first {Name}.
109
- // 2. Let {type} be the type in the {schema} named {typeName}.
108
+ // 1. Let {typeName} be the value of {Name}.
110
109
const typeName = schemaCoordinate . name . value ;
111
110
const type = schema . getType ( typeName ) ;
112
111
113
- // 3. If { type} does not exist, return {null}.
114
- if ( ! type ) {
112
+ // 2. Return the type in the {schema} named {typeName}, or {null} if no such type exists .
113
+ if ( type == null ) {
115
114
return ;
116
115
}
117
116
118
- // 4. {type}
119
117
return { kind : 'NamedType' , type } ;
120
118
}
121
119
122
120
/**
123
- * SchemaCoordinate : Name . Name
121
+ * MemberCoordinate : Name . Name
124
122
*/
125
123
function resolveMemberCoordinate (
126
124
schema : GraphQLSchema ,
@@ -131,69 +129,66 @@ function resolveMemberCoordinate(
131
129
const typeName = schemaCoordinate . name . value ;
132
130
const type = schema . getType ( typeName ) ;
133
131
134
- // 3. Assert {type} must exist.
132
+ // 3. Assert: {type} must exist, and must be an Enum, Input Object, Object or Interface type .
135
133
if ( ! type ) {
136
134
throw new Error (
137
135
`Expected ${ inspect ( typeName ) } to be defined as a type in the schema.` ,
138
136
) ;
139
137
}
138
+ if (
139
+ ! isEnumType ( type ) &&
140
+ ! isInputObjectType ( type ) &&
141
+ ! isObjectType ( type ) &&
142
+ ! isInterfaceType ( type )
143
+ ) {
144
+ throw new Error (
145
+ `Expected ${ inspect ( typeName ) } to be an object type, interface type, input object type, or enum type.` ,
146
+ ) ;
147
+ }
140
148
141
149
// 4. If {type} is an Enum type:
142
150
if ( isEnumType ( type ) ) {
143
- // 5. Let {enumValueName} be the value of the second {Name}.
144
- // 6. Let {enumValue} be the enum value of {type} named {enumValueName}.
151
+ // 1. Let {enumValueName} be the value of the second {Name}.
145
152
const enumValueName = schemaCoordinate . memberName . value ;
146
153
const enumValue = type . getValue ( enumValueName ) ;
147
154
148
- // 7. If {enumValue} does not exist, return {null}.
155
+ // 2. Return the enum value of {type} named {enumValueName}, or {null} if no such value exists .
149
156
if ( enumValue == null ) {
150
157
return ;
151
158
}
152
159
153
- // 8. Return {enumValue}
154
160
return { kind : 'EnumValue' , type, enumValue } ;
155
161
}
156
162
157
- // 9 . Otherwise if {type} is an Input Object type:
163
+ // 5 . Otherwise, if {type} is an Input Object type:
158
164
if ( isInputObjectType ( type ) ) {
159
- // 10. Let {inputFieldName} be the value of the second {Name}.
160
- // 11. Let {inputField} be the input field of {type} named {inputFieldName}.
165
+ // 1. Let {inputFieldName} be the value of the second {Name}.
161
166
const inputFieldName = schemaCoordinate . memberName . value ;
162
167
const inputField = type . getFields ( ) [ inputFieldName ] ;
163
168
164
- // 12. If {inputField} does not exist, return {null}.
169
+ // 2. Return the input field of {type} named {inputFieldName}, or {null} if no such input field exists .
165
170
if ( inputField == null ) {
166
171
return ;
167
172
}
168
173
169
- // 13. Return {inputField}
170
174
return { kind : 'InputField' , type, inputField } ;
171
175
}
172
176
173
- // 14. Otherwise:
174
- // 15. Assert {type} must be an Object or Interface type.
175
- if ( ! isObjectType ( type ) && ! isInterfaceType ( type ) ) {
176
- throw new Error (
177
- `Expected ${ inspect ( typeName ) } to be an object type, interface type, input object type, or enum type.` ,
178
- ) ;
179
- }
180
-
181
- // 16. Let {fieldName} be the value of the second {Name}.
182
- // 17. Let {field} be the field of {type} named {fieldName}.
177
+ // 6. Otherwise:
178
+ // 1. Let {fieldName} be the value of the second {Name}.
183
179
const fieldName = schemaCoordinate . memberName . value ;
184
180
const field = type . getFields ( ) [ fieldName ] ;
185
181
186
- // 18. If { field} does not exist, return {null}.
182
+ // 2. Return the field of {type} named {fieldName}, or {null} if no such field exists .
187
183
if ( field == null ) {
188
184
return ;
189
185
}
190
186
191
- // 19. Return {field}
192
187
return { kind : 'Field' , type, field } ;
193
188
}
194
189
195
190
/**
196
- * SchemaCoordinate : Name . Name ( Name : )
191
+ * ArgumentCoordinate : Name . Name ( Name : )
197
192
*/
198
193
function resolveArgumentCoordinate (
199
194
schema : GraphQLSchema ,
@@ -204,71 +199,65 @@ function resolveArgumentCoordinate(
204
199
const typeName = schemaCoordinate . name . value ;
205
200
const type = schema . getType ( typeName ) ;
206
201
207
- // 3. Assert {type} must exist.
202
+ // 3. Assert: {type} must exist, and be an Object or Interface type .
208
203
if ( type == null ) {
209
204
throw new Error (
210
205
`Expected ${ inspect ( typeName ) } to be defined as a type in the schema.` ,
211
206
) ;
212
207
}
213
-
214
- // 4. Assert {type} must be an Object or Interface type.
215
208
if ( ! isObjectType ( type ) && ! isInterfaceType ( type ) ) {
216
209
throw new Error (
217
210
`Expected ${ inspect ( typeName ) } to be an object type or interface type.` ,
218
211
) ;
219
212
}
220
213
221
- // 5 . Let {fieldName} be the value of the second {Name}.
222
- // 6 . Let {field} be the field of {type} named {fieldName}.
214
+ // 4 . Let {fieldName} be the value of the second {Name}.
215
+ // 5 . Let {field} be the field of {type} named {fieldName}.
223
216
const fieldName = schemaCoordinate . fieldName . value ;
224
217
const field = type . getFields ( ) [ fieldName ] ;
225
218
226
- // 7. Assert {field} must exist.
219
+ // 7. Assert: {field} must exist.
227
220
if ( field == null ) {
228
221
throw new Error (
229
222
`Expected ${ inspect ( fieldName ) } to exist as a field of type ${ inspect ( typeName ) } in the schema.` ,
230
223
) ;
231
224
}
232
225
233
- // 8. Let {fieldArgumentName} be the value of the third {Name}.
234
- // 9. Let {fieldArgument} be the argument of {field} named {fieldArgumentName}.
226
+ // 7. Let {fieldArgumentName} be the value of the third {Name}.
235
227
const fieldArgumentName = schemaCoordinate . argumentName . value ;
236
228
const fieldArgument = field . args . find (
237
229
( arg ) => arg . name === fieldArgumentName ,
238
230
) ;
239
231
240
- // 10. If {fieldArgument} does not exist, return {null}.
232
+ // 8. Return the argument of {field} named {fieldArgumentName}, or {null} if no such argument exists .
241
233
if ( fieldArgument == null ) {
242
234
return ;
243
235
}
244
236
245
- // 11. Return {fieldArgument}.
246
237
return { kind : 'FieldArgument' , type, field, fieldArgument } ;
247
238
}
248
239
249
240
/**
250
- * SchemaCoordinate : @ Name
241
+ * DirectiveCoordinate : @ Name
251
242
*/
252
243
function resolveDirectiveCoordinate (
253
244
schema : GraphQLSchema ,
254
245
schemaCoordinate : DirectiveCoordinateNode ,
255
246
) : ResolvedDirective | undefined {
256
- // 1. Let {directiveName} be the value of the first {Name}.
257
- // 2. Let {directive} be the directive in the {schema} named {directiveName}.
247
+ // 1. Let {directiveName} be the value of {Name}.
258
248
const directiveName = schemaCoordinate . name . value ;
259
249
const directive = schema . getDirective ( directiveName ) ;
260
250
261
- // 3. If { directive} does not exist, return {null}.
251
+ // 2. Return the directive in the {schema} named {directiveName}, or {null} if no such directive exists .
262
252
if ( ! directive ) {
263
253
return ;
264
254
}
265
255
266
- // 4. Otherwise return {directive}.
267
256
return { kind : 'Directive' , directive } ;
268
257
}
269
258
270
259
/**
271
- * SchemaCoordinate : @ Name ( Name : )
260
+ * DirectiveArgumentCoordinate : @ Name ( Name : )
272
261
*/
273
262
function resolveDirectiveArgumentCoordinate (
274
263
schema : GraphQLSchema ,
@@ -287,20 +276,18 @@ function resolveDirectiveArgumentCoordinate(
287
276
}
288
277
289
278
// 4. Let {directiveArgumentName} be the value of the second {Name}.
290
- // 5. Let {directiveArgument} be the argument of {directive} named {directiveArgumentName}.
291
279
const {
292
280
argumentName : { value : directiveArgumentName } ,
293
281
} = schemaCoordinate ;
294
282
const directiveArgument = directive . args . find (
295
283
( arg ) => arg . name === directiveArgumentName ,
296
284
) ;
297
285
298
- // 6. If {directiveArgument} does not exist, return {null}.
286
+ // 5. Return the argument of {directive} named {directiveArgumentName}, or {null} if no such argument exists .
299
287
if ( ! directiveArgument ) {
300
288
return ;
301
289
}
302
290
303
- // 7. Return {directiveArgument}.
304
291
return { kind : 'DirectiveArgument' , directive, directiveArgument } ;
305
292
}
306
293
0 commit comments