Skip to content

Commit cc9df08

Browse files
committed
update to use spec wording
1 parent a49e236 commit cc9df08

File tree

1 file changed

+36
-49
lines changed

1 file changed

+36
-49
lines changed

src/utilities/resolveSchemaCoordinate.ts

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,26 @@ export function resolveSchemaCoordinate(
9999
}
100100

101101
/**
102-
* SchemaCoordinate : Name
102+
* TypeCoordinate : Name
103103
*/
104104
function resolveTypeCoordinate(
105105
schema: GraphQLSchema,
106106
schemaCoordinate: TypeCoordinateNode,
107107
): 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}.
110109
const typeName = schemaCoordinate.name.value;
111110
const type = schema.getType(typeName);
112111

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) {
115114
return;
116115
}
117116

118-
// 4. {type}
119117
return { kind: 'NamedType', type };
120118
}
121119

122120
/**
123-
* SchemaCoordinate : Name . Name
121+
* MemberCoordinate : Name . Name
124122
*/
125123
function resolveMemberCoordinate(
126124
schema: GraphQLSchema,
@@ -131,69 +129,66 @@ function resolveMemberCoordinate(
131129
const typeName = schemaCoordinate.name.value;
132130
const type = schema.getType(typeName);
133131

134-
// 3. Assert {type} must exist.
132+
// 3. Assert: {type} must exist, and must be an Enum, Input Object, Object or Interface type.
135133
if (!type) {
136134
throw new Error(
137135
`Expected ${inspect(typeName)} to be defined as a type in the schema.`,
138136
);
139137
}
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+
}
140148

141149
// 4. If {type} is an Enum type:
142150
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}.
145152
const enumValueName = schemaCoordinate.memberName.value;
146153
const enumValue = type.getValue(enumValueName);
147154

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.
149156
if (enumValue == null) {
150157
return;
151158
}
152159

153-
// 8. Return {enumValue}
154160
return { kind: 'EnumValue', type, enumValue };
155161
}
156162

157-
// 9. Otherwise if {type} is an Input Object type:
163+
// 5. Otherwise, if {type} is an Input Object type:
158164
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}.
161166
const inputFieldName = schemaCoordinate.memberName.value;
162167
const inputField = type.getFields()[inputFieldName];
163168

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.
165170
if (inputField == null) {
166171
return;
167172
}
168173

169-
// 13. Return {inputField}
170174
return { kind: 'InputField', type, inputField };
171175
}
172176

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}.
183179
const fieldName = schemaCoordinate.memberName.value;
184180
const field = type.getFields()[fieldName];
185181

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.
187183
if (field == null) {
188184
return;
189185
}
190186

191-
// 19. Return {field}
192187
return { kind: 'Field', type, field };
193188
}
194189

195190
/**
196-
* SchemaCoordinate : Name . Name ( Name : )
191+
* ArgumentCoordinate : Name . Name ( Name : )
197192
*/
198193
function resolveArgumentCoordinate(
199194
schema: GraphQLSchema,
@@ -204,71 +199,65 @@ function resolveArgumentCoordinate(
204199
const typeName = schemaCoordinate.name.value;
205200
const type = schema.getType(typeName);
206201

207-
// 3. Assert {type} must exist.
202+
// 3. Assert: {type} must exist, and be an Object or Interface type.
208203
if (type == null) {
209204
throw new Error(
210205
`Expected ${inspect(typeName)} to be defined as a type in the schema.`,
211206
);
212207
}
213-
214-
// 4. Assert {type} must be an Object or Interface type.
215208
if (!isObjectType(type) && !isInterfaceType(type)) {
216209
throw new Error(
217210
`Expected ${inspect(typeName)} to be an object type or interface type.`,
218211
);
219212
}
220213

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}.
223216
const fieldName = schemaCoordinate.fieldName.value;
224217
const field = type.getFields()[fieldName];
225218

226-
// 7. Assert {field} must exist.
219+
// 7. Assert: {field} must exist.
227220
if (field == null) {
228221
throw new Error(
229222
`Expected ${inspect(fieldName)} to exist as a field of type ${inspect(typeName)} in the schema.`,
230223
);
231224
}
232225

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}.
235227
const fieldArgumentName = schemaCoordinate.argumentName.value;
236228
const fieldArgument = field.args.find(
237229
(arg) => arg.name === fieldArgumentName,
238230
);
239231

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.
241233
if (fieldArgument == null) {
242234
return;
243235
}
244236

245-
// 11. Return {fieldArgument}.
246237
return { kind: 'FieldArgument', type, field, fieldArgument };
247238
}
248239

249240
/**
250-
* SchemaCoordinate : @ Name
241+
* DirectiveCoordinate : @ Name
251242
*/
252243
function resolveDirectiveCoordinate(
253244
schema: GraphQLSchema,
254245
schemaCoordinate: DirectiveCoordinateNode,
255246
): 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}.
258248
const directiveName = schemaCoordinate.name.value;
259249
const directive = schema.getDirective(directiveName);
260250

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.
262252
if (!directive) {
263253
return;
264254
}
265255

266-
// 4. Otherwise return {directive}.
267256
return { kind: 'Directive', directive };
268257
}
269258

270259
/**
271-
* SchemaCoordinate : @ Name ( Name : )
260+
* DirectiveArgumentCoordinate : @ Name ( Name : )
272261
*/
273262
function resolveDirectiveArgumentCoordinate(
274263
schema: GraphQLSchema,
@@ -287,20 +276,18 @@ function resolveDirectiveArgumentCoordinate(
287276
}
288277

289278
// 4. Let {directiveArgumentName} be the value of the second {Name}.
290-
// 5. Let {directiveArgument} be the argument of {directive} named {directiveArgumentName}.
291279
const {
292280
argumentName: { value: directiveArgumentName },
293281
} = schemaCoordinate;
294282
const directiveArgument = directive.args.find(
295283
(arg) => arg.name === directiveArgumentName,
296284
);
297285

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.
299287
if (!directiveArgument) {
300288
return;
301289
}
302290

303-
// 7. Return {directiveArgument}.
304291
return { kind: 'DirectiveArgument', directive, directiveArgument };
305292
}
306293

0 commit comments

Comments
 (0)