graphql 14.1.0 → 14.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utilities/buildASTSchema.js +116 -99
- package/utilities/buildASTSchema.js.flow +106 -86
- package/utilities/buildASTSchema.mjs +115 -97
package/package.json
CHANGED
|
@@ -229,38 +229,60 @@ function () {
|
|
|
229
229
|
return this.buildType(typeNode);
|
|
230
230
|
};
|
|
231
231
|
|
|
232
|
-
_proto.buildDirective = function buildDirective(
|
|
232
|
+
_proto.buildDirective = function buildDirective(directive) {
|
|
233
|
+
var _this = this;
|
|
234
|
+
|
|
235
|
+
var locations = directive.locations.map(function (_ref) {
|
|
236
|
+
var value = _ref.value;
|
|
237
|
+
return value;
|
|
238
|
+
});
|
|
233
239
|
return new _directives.GraphQLDirective({
|
|
234
|
-
name:
|
|
235
|
-
description: getDescription(
|
|
236
|
-
locations:
|
|
237
|
-
|
|
240
|
+
name: directive.name.value,
|
|
241
|
+
description: getDescription(directive, this._options),
|
|
242
|
+
locations: locations,
|
|
243
|
+
args: keyByNameNode(directive.arguments || [], function (arg) {
|
|
244
|
+
return _this.buildArg(arg);
|
|
238
245
|
}),
|
|
239
|
-
|
|
240
|
-
astNode: directiveNode
|
|
246
|
+
astNode: directive
|
|
241
247
|
});
|
|
242
248
|
};
|
|
243
249
|
|
|
244
250
|
_proto.buildField = function buildField(field) {
|
|
251
|
+
var _this2 = this;
|
|
252
|
+
|
|
245
253
|
return {
|
|
246
254
|
// Note: While this could make assertions to get the correctly typed
|
|
247
255
|
// value, that would throw immediately while type system validation
|
|
248
256
|
// with validateSchema() will produce more actionable results.
|
|
249
257
|
type: this._buildWrappedType(field.type),
|
|
250
258
|
description: getDescription(field, this._options),
|
|
251
|
-
args: field.arguments
|
|
259
|
+
args: keyByNameNode(field.arguments || [], function (arg) {
|
|
260
|
+
return _this2.buildArg(arg);
|
|
261
|
+
}),
|
|
252
262
|
deprecationReason: getDeprecationReason(field),
|
|
253
263
|
astNode: field
|
|
254
264
|
};
|
|
255
265
|
};
|
|
256
266
|
|
|
267
|
+
_proto.buildArg = function buildArg(value) {
|
|
268
|
+
// Note: While this could make assertions to get the correctly typed
|
|
269
|
+
// value, that would throw immediately while type system validation
|
|
270
|
+
var type = this._buildWrappedType(value.type);
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
type: type,
|
|
274
|
+
description: getDescription(value, this._options),
|
|
275
|
+
defaultValue: (0, _valueFromAST.valueFromAST)(value.defaultValue, type),
|
|
276
|
+
astNode: value
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
|
|
257
280
|
_proto.buildInputField = function buildInputField(value) {
|
|
258
281
|
// Note: While this could make assertions to get the correctly typed
|
|
259
282
|
// value, that would throw immediately while type system validation
|
|
260
283
|
var type = this._buildWrappedType(value.type);
|
|
261
284
|
|
|
262
285
|
return {
|
|
263
|
-
name: value.name.value,
|
|
264
286
|
type: type,
|
|
265
287
|
description: getDescription(value, this._options),
|
|
266
288
|
defaultValue: (0, _valueFromAST.valueFromAST)(value.defaultValue, type),
|
|
@@ -276,129 +298,114 @@ function () {
|
|
|
276
298
|
};
|
|
277
299
|
};
|
|
278
300
|
|
|
279
|
-
_proto._makeSchemaDef = function _makeSchemaDef(
|
|
280
|
-
switch (
|
|
301
|
+
_proto._makeSchemaDef = function _makeSchemaDef(astNode) {
|
|
302
|
+
switch (astNode.kind) {
|
|
281
303
|
case _kinds.Kind.OBJECT_TYPE_DEFINITION:
|
|
282
|
-
return this._makeTypeDef(
|
|
304
|
+
return this._makeTypeDef(astNode);
|
|
283
305
|
|
|
284
306
|
case _kinds.Kind.INTERFACE_TYPE_DEFINITION:
|
|
285
|
-
return this._makeInterfaceDef(
|
|
307
|
+
return this._makeInterfaceDef(astNode);
|
|
286
308
|
|
|
287
309
|
case _kinds.Kind.ENUM_TYPE_DEFINITION:
|
|
288
|
-
return this._makeEnumDef(
|
|
310
|
+
return this._makeEnumDef(astNode);
|
|
289
311
|
|
|
290
312
|
case _kinds.Kind.UNION_TYPE_DEFINITION:
|
|
291
|
-
return this._makeUnionDef(
|
|
313
|
+
return this._makeUnionDef(astNode);
|
|
292
314
|
|
|
293
315
|
case _kinds.Kind.SCALAR_TYPE_DEFINITION:
|
|
294
|
-
return this._makeScalarDef(
|
|
316
|
+
return this._makeScalarDef(astNode);
|
|
295
317
|
|
|
296
318
|
case _kinds.Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
297
|
-
return this._makeInputObjectDef(
|
|
319
|
+
return this._makeInputObjectDef(astNode);
|
|
298
320
|
|
|
299
321
|
default:
|
|
300
|
-
throw new Error("Type kind \"".concat(
|
|
322
|
+
throw new Error("Type kind \"".concat(astNode.kind, "\" not supported."));
|
|
301
323
|
}
|
|
302
324
|
};
|
|
303
325
|
|
|
304
|
-
_proto._makeTypeDef = function _makeTypeDef(
|
|
305
|
-
var _this = this;
|
|
306
|
-
|
|
307
|
-
var interfaces = def.interfaces;
|
|
308
|
-
return new _definition.GraphQLObjectType({
|
|
309
|
-
name: def.name.value,
|
|
310
|
-
description: getDescription(def, this._options),
|
|
311
|
-
fields: function fields() {
|
|
312
|
-
return _this._makeFieldDefMap(def);
|
|
313
|
-
},
|
|
314
|
-
// Note: While this could make early assertions to get the correctly
|
|
315
|
-
// typed values, that would throw immediately while type system
|
|
316
|
-
// validation with validateSchema() will produce more actionable results.
|
|
317
|
-
interfaces: interfaces ? function () {
|
|
318
|
-
return interfaces.map(function (ref) {
|
|
319
|
-
return _this.buildType(ref);
|
|
320
|
-
});
|
|
321
|
-
} : [],
|
|
322
|
-
astNode: def
|
|
323
|
-
});
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
_proto._makeFieldDefMap = function _makeFieldDefMap(def) {
|
|
327
|
-
var _this2 = this;
|
|
328
|
-
|
|
329
|
-
return def.fields ? (0, _keyValMap.default)(def.fields, function (field) {
|
|
330
|
-
return field.name.value;
|
|
331
|
-
}, function (field) {
|
|
332
|
-
return _this2.buildField(field);
|
|
333
|
-
}) : {};
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
_proto._makeInputValues = function _makeInputValues(values) {
|
|
326
|
+
_proto._makeTypeDef = function _makeTypeDef(astNode) {
|
|
337
327
|
var _this3 = this;
|
|
338
328
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
329
|
+
var interfaceNodes = astNode.interfaces;
|
|
330
|
+
var fieldNodes = astNode.fields; // Note: While this could make assertions to get the correctly typed
|
|
331
|
+
// values below, that would throw immediately while type system
|
|
332
|
+
// validation with validateSchema() will produce more actionable results.
|
|
333
|
+
|
|
334
|
+
var interfaces = interfaceNodes && interfaceNodes.length > 0 ? function () {
|
|
335
|
+
return interfaceNodes.map(function (ref) {
|
|
336
|
+
return _this3.buildType(ref);
|
|
337
|
+
});
|
|
338
|
+
} : [];
|
|
339
|
+
var fields = fieldNodes && fieldNodes.length > 0 ? function () {
|
|
340
|
+
return keyByNameNode(fieldNodes, function (field) {
|
|
341
|
+
return _this3.buildField(field);
|
|
342
|
+
});
|
|
343
|
+
} : Object.create(null);
|
|
344
|
+
return new _definition.GraphQLObjectType({
|
|
345
|
+
name: astNode.name.value,
|
|
346
|
+
description: getDescription(astNode, this._options),
|
|
347
|
+
interfaces: interfaces,
|
|
348
|
+
fields: fields,
|
|
349
|
+
astNode: astNode
|
|
343
350
|
});
|
|
344
351
|
};
|
|
345
352
|
|
|
346
|
-
_proto._makeInterfaceDef = function _makeInterfaceDef(
|
|
353
|
+
_proto._makeInterfaceDef = function _makeInterfaceDef(astNode) {
|
|
347
354
|
var _this4 = this;
|
|
348
355
|
|
|
356
|
+
var fieldNodes = astNode.fields;
|
|
357
|
+
var fields = fieldNodes && fieldNodes.length > 0 ? function () {
|
|
358
|
+
return keyByNameNode(fieldNodes, function (field) {
|
|
359
|
+
return _this4.buildField(field);
|
|
360
|
+
});
|
|
361
|
+
} : Object.create(null);
|
|
349
362
|
return new _definition.GraphQLInterfaceType({
|
|
350
|
-
name:
|
|
351
|
-
description: getDescription(
|
|
352
|
-
fields:
|
|
353
|
-
|
|
354
|
-
},
|
|
355
|
-
astNode: def
|
|
363
|
+
name: astNode.name.value,
|
|
364
|
+
description: getDescription(astNode, this._options),
|
|
365
|
+
fields: fields,
|
|
366
|
+
astNode: astNode
|
|
356
367
|
});
|
|
357
368
|
};
|
|
358
369
|
|
|
359
|
-
_proto._makeEnumDef = function _makeEnumDef(
|
|
360
|
-
return new _definition.GraphQLEnumType({
|
|
361
|
-
name: def.name.value,
|
|
362
|
-
description: getDescription(def, this._options),
|
|
363
|
-
values: this._makeValueDefMap(def),
|
|
364
|
-
astNode: def
|
|
365
|
-
});
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
_proto._makeValueDefMap = function _makeValueDefMap(def) {
|
|
370
|
+
_proto._makeEnumDef = function _makeEnumDef(astNode) {
|
|
369
371
|
var _this5 = this;
|
|
370
372
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
373
|
+
var valueNodes = astNode.values || [];
|
|
374
|
+
return new _definition.GraphQLEnumType({
|
|
375
|
+
name: astNode.name.value,
|
|
376
|
+
description: getDescription(astNode, this._options),
|
|
377
|
+
values: keyByNameNode(valueNodes, function (value) {
|
|
378
|
+
return _this5.buildEnumValue(value);
|
|
379
|
+
}),
|
|
380
|
+
astNode: astNode
|
|
381
|
+
});
|
|
376
382
|
};
|
|
377
383
|
|
|
378
|
-
_proto._makeUnionDef = function _makeUnionDef(
|
|
384
|
+
_proto._makeUnionDef = function _makeUnionDef(astNode) {
|
|
379
385
|
var _this6 = this;
|
|
380
386
|
|
|
381
|
-
var
|
|
387
|
+
var typeNodes = astNode.types; // Note: While this could make assertions to get the correctly typed
|
|
388
|
+
// values below, that would throw immediately while type system
|
|
389
|
+
// validation with validateSchema() will produce more actionable results.
|
|
390
|
+
|
|
391
|
+
var types = typeNodes && typeNodes.length > 0 ? function () {
|
|
392
|
+
return typeNodes.map(function (ref) {
|
|
393
|
+
return _this6.buildType(ref);
|
|
394
|
+
});
|
|
395
|
+
} : [];
|
|
382
396
|
return new _definition.GraphQLUnionType({
|
|
383
|
-
name:
|
|
384
|
-
description: getDescription(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
// validation with validateSchema() will produce more actionable results.
|
|
388
|
-
types: types ? function () {
|
|
389
|
-
return types.map(function (ref) {
|
|
390
|
-
return _this6.buildType(ref);
|
|
391
|
-
});
|
|
392
|
-
} : [],
|
|
393
|
-
astNode: def
|
|
397
|
+
name: astNode.name.value,
|
|
398
|
+
description: getDescription(astNode, this._options),
|
|
399
|
+
types: types,
|
|
400
|
+
astNode: astNode
|
|
394
401
|
});
|
|
395
402
|
};
|
|
396
403
|
|
|
397
|
-
_proto._makeScalarDef = function _makeScalarDef(
|
|
404
|
+
_proto._makeScalarDef = function _makeScalarDef(astNode) {
|
|
398
405
|
return new _definition.GraphQLScalarType({
|
|
399
|
-
name:
|
|
400
|
-
description: getDescription(
|
|
401
|
-
astNode:
|
|
406
|
+
name: astNode.name.value,
|
|
407
|
+
description: getDescription(astNode, this._options),
|
|
408
|
+
astNode: astNode,
|
|
402
409
|
serialize: function serialize(value) {
|
|
403
410
|
return value;
|
|
404
411
|
}
|
|
@@ -408,26 +415,36 @@ function () {
|
|
|
408
415
|
_proto._makeInputObjectDef = function _makeInputObjectDef(def) {
|
|
409
416
|
var _this7 = this;
|
|
410
417
|
|
|
418
|
+
var fields = def.fields;
|
|
411
419
|
return new _definition.GraphQLInputObjectType({
|
|
412
420
|
name: def.name.value,
|
|
413
421
|
description: getDescription(def, this._options),
|
|
414
|
-
fields: function
|
|
415
|
-
return
|
|
416
|
-
|
|
422
|
+
fields: fields ? function () {
|
|
423
|
+
return keyByNameNode(fields, function (field) {
|
|
424
|
+
return _this7.buildInputField(field);
|
|
425
|
+
});
|
|
426
|
+
} : Object.create(null),
|
|
417
427
|
astNode: def
|
|
418
428
|
});
|
|
419
429
|
};
|
|
420
430
|
|
|
421
431
|
return ASTDefinitionBuilder;
|
|
422
432
|
}();
|
|
433
|
+
|
|
434
|
+
exports.ASTDefinitionBuilder = ASTDefinitionBuilder;
|
|
435
|
+
|
|
436
|
+
function keyByNameNode(list, valFn) {
|
|
437
|
+
return (0, _keyValMap.default)(list, function (_ref2) {
|
|
438
|
+
var name = _ref2.name;
|
|
439
|
+
return name.value;
|
|
440
|
+
}, valFn);
|
|
441
|
+
}
|
|
423
442
|
/**
|
|
424
443
|
* Given a field or enum value node, returns the string value for the
|
|
425
444
|
* deprecation reason.
|
|
426
445
|
*/
|
|
427
446
|
|
|
428
447
|
|
|
429
|
-
exports.ASTDefinitionBuilder = ASTDefinitionBuilder;
|
|
430
|
-
|
|
431
448
|
function getDeprecationReason(node) {
|
|
432
449
|
var deprecated = (0, _values.getDirectiveValues)(_directives.GraphQLDeprecatedDirective, node);
|
|
433
450
|
return deprecated && deprecated.reason;
|
|
@@ -24,6 +24,7 @@ import { Kind } from '../language/kinds';
|
|
|
24
24
|
|
|
25
25
|
import type {
|
|
26
26
|
DocumentNode,
|
|
27
|
+
NameNode,
|
|
27
28
|
TypeNode,
|
|
28
29
|
NamedTypeNode,
|
|
29
30
|
SchemaDefinitionNode,
|
|
@@ -49,8 +50,9 @@ import type {
|
|
|
49
50
|
GraphQLType,
|
|
50
51
|
GraphQLNamedType,
|
|
51
52
|
GraphQLFieldConfig,
|
|
53
|
+
GraphQLArgumentConfig,
|
|
52
54
|
GraphQLEnumValueConfig,
|
|
53
|
-
|
|
55
|
+
GraphQLInputFieldConfig,
|
|
54
56
|
} from '../type/definition';
|
|
55
57
|
|
|
56
58
|
import {
|
|
@@ -256,17 +258,17 @@ export class ASTDefinitionBuilder {
|
|
|
256
258
|
return this.buildType(typeNode);
|
|
257
259
|
}
|
|
258
260
|
|
|
259
|
-
buildDirective(
|
|
261
|
+
buildDirective(directive: DirectiveDefinitionNode): GraphQLDirective {
|
|
262
|
+
const locations = directive.locations.map(
|
|
263
|
+
({ value }) => ((value: any): DirectiveLocationEnum),
|
|
264
|
+
);
|
|
265
|
+
|
|
260
266
|
return new GraphQLDirective({
|
|
261
|
-
name:
|
|
262
|
-
description: getDescription(
|
|
263
|
-
locations
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
args:
|
|
267
|
-
directiveNode.arguments &&
|
|
268
|
-
this._makeInputValues(directiveNode.arguments),
|
|
269
|
-
astNode: directiveNode,
|
|
267
|
+
name: directive.name.value,
|
|
268
|
+
description: getDescription(directive, this._options),
|
|
269
|
+
locations,
|
|
270
|
+
args: keyByNameNode(directive.arguments || [], arg => this.buildArg(arg)),
|
|
271
|
+
astNode: directive,
|
|
270
272
|
});
|
|
271
273
|
}
|
|
272
274
|
|
|
@@ -277,19 +279,31 @@ export class ASTDefinitionBuilder {
|
|
|
277
279
|
// with validateSchema() will produce more actionable results.
|
|
278
280
|
type: (this._buildWrappedType(field.type): any),
|
|
279
281
|
description: getDescription(field, this._options),
|
|
280
|
-
args: field.arguments
|
|
282
|
+
args: keyByNameNode(field.arguments || [], arg => this.buildArg(arg)),
|
|
281
283
|
deprecationReason: getDeprecationReason(field),
|
|
282
284
|
astNode: field,
|
|
283
285
|
};
|
|
284
286
|
}
|
|
285
287
|
|
|
286
|
-
|
|
288
|
+
buildArg(value: InputValueDefinitionNode): GraphQLArgumentConfig {
|
|
289
|
+
// Note: While this could make assertions to get the correctly typed
|
|
290
|
+
// value, that would throw immediately while type system validation
|
|
291
|
+
// with validateSchema() will produce more actionable results.
|
|
292
|
+
const type: any = this._buildWrappedType(value.type);
|
|
293
|
+
return {
|
|
294
|
+
type,
|
|
295
|
+
description: getDescription(value, this._options),
|
|
296
|
+
defaultValue: valueFromAST(value.defaultValue, type),
|
|
297
|
+
astNode: value,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
buildInputField(value: InputValueDefinitionNode): GraphQLInputFieldConfig {
|
|
287
302
|
// Note: While this could make assertions to get the correctly typed
|
|
288
303
|
// value, that would throw immediately while type system validation
|
|
289
304
|
// with validateSchema() will produce more actionable results.
|
|
290
305
|
const type: any = this._buildWrappedType(value.type);
|
|
291
306
|
return {
|
|
292
|
-
name: value.name.value,
|
|
293
307
|
type,
|
|
294
308
|
description: getDescription(value, this._options),
|
|
295
309
|
defaultValue: valueFromAST(value.defaultValue, type),
|
|
@@ -305,121 +319,127 @@ export class ASTDefinitionBuilder {
|
|
|
305
319
|
};
|
|
306
320
|
}
|
|
307
321
|
|
|
308
|
-
_makeSchemaDef(
|
|
309
|
-
switch (
|
|
322
|
+
_makeSchemaDef(astNode: TypeDefinitionNode): GraphQLNamedType {
|
|
323
|
+
switch (astNode.kind) {
|
|
310
324
|
case Kind.OBJECT_TYPE_DEFINITION:
|
|
311
|
-
return this._makeTypeDef(
|
|
325
|
+
return this._makeTypeDef(astNode);
|
|
312
326
|
case Kind.INTERFACE_TYPE_DEFINITION:
|
|
313
|
-
return this._makeInterfaceDef(
|
|
327
|
+
return this._makeInterfaceDef(astNode);
|
|
314
328
|
case Kind.ENUM_TYPE_DEFINITION:
|
|
315
|
-
return this._makeEnumDef(
|
|
329
|
+
return this._makeEnumDef(astNode);
|
|
316
330
|
case Kind.UNION_TYPE_DEFINITION:
|
|
317
|
-
return this._makeUnionDef(
|
|
331
|
+
return this._makeUnionDef(astNode);
|
|
318
332
|
case Kind.SCALAR_TYPE_DEFINITION:
|
|
319
|
-
return this._makeScalarDef(
|
|
333
|
+
return this._makeScalarDef(astNode);
|
|
320
334
|
case Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
321
|
-
return this._makeInputObjectDef(
|
|
335
|
+
return this._makeInputObjectDef(astNode);
|
|
322
336
|
default:
|
|
323
|
-
throw new Error(`Type kind "${
|
|
337
|
+
throw new Error(`Type kind "${astNode.kind}" not supported.`);
|
|
324
338
|
}
|
|
325
339
|
}
|
|
326
340
|
|
|
327
|
-
_makeTypeDef(
|
|
328
|
-
const
|
|
341
|
+
_makeTypeDef(astNode: ObjectTypeDefinitionNode) {
|
|
342
|
+
const interfaceNodes = astNode.interfaces;
|
|
343
|
+
const fieldNodes = astNode.fields;
|
|
344
|
+
|
|
345
|
+
// Note: While this could make assertions to get the correctly typed
|
|
346
|
+
// values below, that would throw immediately while type system
|
|
347
|
+
// validation with validateSchema() will produce more actionable results.
|
|
348
|
+
const interfaces =
|
|
349
|
+
interfaceNodes && interfaceNodes.length > 0
|
|
350
|
+
? () => interfaceNodes.map(ref => (this.buildType(ref): any))
|
|
351
|
+
: [];
|
|
352
|
+
|
|
353
|
+
const fields =
|
|
354
|
+
fieldNodes && fieldNodes.length > 0
|
|
355
|
+
? () => keyByNameNode(fieldNodes, field => this.buildField(field))
|
|
356
|
+
: Object.create(null);
|
|
357
|
+
|
|
329
358
|
return new GraphQLObjectType({
|
|
330
|
-
name:
|
|
331
|
-
description: getDescription(
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
// validation with validateSchema() will produce more actionable results.
|
|
336
|
-
interfaces: interfaces
|
|
337
|
-
? () => interfaces.map(ref => (this.buildType(ref): any))
|
|
338
|
-
: [],
|
|
339
|
-
astNode: def,
|
|
359
|
+
name: astNode.name.value,
|
|
360
|
+
description: getDescription(astNode, this._options),
|
|
361
|
+
interfaces,
|
|
362
|
+
fields,
|
|
363
|
+
astNode,
|
|
340
364
|
});
|
|
341
365
|
}
|
|
342
366
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
) {
|
|
346
|
-
return def.fields
|
|
347
|
-
? keyValMap<_, GraphQLFieldConfig<mixed, mixed>>(
|
|
348
|
-
def.fields,
|
|
349
|
-
field => field.name.value,
|
|
350
|
-
field => this.buildField(field),
|
|
351
|
-
)
|
|
352
|
-
: {};
|
|
353
|
-
}
|
|
367
|
+
_makeInterfaceDef(astNode: InterfaceTypeDefinitionNode) {
|
|
368
|
+
const fieldNodes = astNode.fields;
|
|
354
369
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
value => this.buildInputField(value),
|
|
360
|
-
);
|
|
361
|
-
}
|
|
370
|
+
const fields =
|
|
371
|
+
fieldNodes && fieldNodes.length > 0
|
|
372
|
+
? () => keyByNameNode(fieldNodes, field => this.buildField(field))
|
|
373
|
+
: Object.create(null);
|
|
362
374
|
|
|
363
|
-
_makeInterfaceDef(def: InterfaceTypeDefinitionNode) {
|
|
364
375
|
return new GraphQLInterfaceType({
|
|
365
|
-
name:
|
|
366
|
-
description: getDescription(
|
|
367
|
-
fields
|
|
368
|
-
astNode
|
|
376
|
+
name: astNode.name.value,
|
|
377
|
+
description: getDescription(astNode, this._options),
|
|
378
|
+
fields,
|
|
379
|
+
astNode,
|
|
369
380
|
});
|
|
370
381
|
}
|
|
371
382
|
|
|
372
|
-
_makeEnumDef(
|
|
383
|
+
_makeEnumDef(astNode: EnumTypeDefinitionNode) {
|
|
384
|
+
const valueNodes = astNode.values || [];
|
|
385
|
+
|
|
373
386
|
return new GraphQLEnumType({
|
|
374
|
-
name:
|
|
375
|
-
description: getDescription(
|
|
376
|
-
values: this.
|
|
377
|
-
astNode
|
|
387
|
+
name: astNode.name.value,
|
|
388
|
+
description: getDescription(astNode, this._options),
|
|
389
|
+
values: keyByNameNode(valueNodes, value => this.buildEnumValue(value)),
|
|
390
|
+
astNode,
|
|
378
391
|
});
|
|
379
392
|
}
|
|
380
393
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
394
|
+
_makeUnionDef(astNode: UnionTypeDefinitionNode) {
|
|
395
|
+
const typeNodes = astNode.types;
|
|
396
|
+
|
|
397
|
+
// Note: While this could make assertions to get the correctly typed
|
|
398
|
+
// values below, that would throw immediately while type system
|
|
399
|
+
// validation with validateSchema() will produce more actionable results.
|
|
400
|
+
const types =
|
|
401
|
+
typeNodes && typeNodes.length > 0
|
|
402
|
+
? () => typeNodes.map(ref => (this.buildType(ref): any))
|
|
403
|
+
: [];
|
|
390
404
|
|
|
391
|
-
_makeUnionDef(def: UnionTypeDefinitionNode) {
|
|
392
|
-
const types: ?$ReadOnlyArray<NamedTypeNode> = def.types;
|
|
393
405
|
return new GraphQLUnionType({
|
|
394
|
-
name:
|
|
395
|
-
description: getDescription(
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
// validation with validateSchema() will produce more actionable results.
|
|
399
|
-
types: types ? () => types.map(ref => (this.buildType(ref): any)) : [],
|
|
400
|
-
astNode: def,
|
|
406
|
+
name: astNode.name.value,
|
|
407
|
+
description: getDescription(astNode, this._options),
|
|
408
|
+
types,
|
|
409
|
+
astNode,
|
|
401
410
|
});
|
|
402
411
|
}
|
|
403
412
|
|
|
404
|
-
_makeScalarDef(
|
|
413
|
+
_makeScalarDef(astNode: ScalarTypeDefinitionNode) {
|
|
405
414
|
return new GraphQLScalarType({
|
|
406
|
-
name:
|
|
407
|
-
description: getDescription(
|
|
408
|
-
astNode
|
|
415
|
+
name: astNode.name.value,
|
|
416
|
+
description: getDescription(astNode, this._options),
|
|
417
|
+
astNode,
|
|
409
418
|
serialize: value => value,
|
|
410
419
|
});
|
|
411
420
|
}
|
|
412
421
|
|
|
413
422
|
_makeInputObjectDef(def: InputObjectTypeDefinitionNode) {
|
|
423
|
+
const { fields } = def;
|
|
424
|
+
|
|
414
425
|
return new GraphQLInputObjectType({
|
|
415
426
|
name: def.name.value,
|
|
416
427
|
description: getDescription(def, this._options),
|
|
417
|
-
fields:
|
|
428
|
+
fields: fields
|
|
429
|
+
? () => keyByNameNode(fields, field => this.buildInputField(field))
|
|
430
|
+
: Object.create(null),
|
|
418
431
|
astNode: def,
|
|
419
432
|
});
|
|
420
433
|
}
|
|
421
434
|
}
|
|
422
435
|
|
|
436
|
+
function keyByNameNode<T: { +name: NameNode }, V>(
|
|
437
|
+
list: $ReadOnlyArray<T>,
|
|
438
|
+
valFn: (item: T) => V,
|
|
439
|
+
): ObjMap<V> {
|
|
440
|
+
return keyValMap(list, ({ name }) => name.value, valFn);
|
|
441
|
+
}
|
|
442
|
+
|
|
423
443
|
/**
|
|
424
444
|
* Given a field or enum value node, returns the string value for the
|
|
425
445
|
* deprecation reason.
|
|
@@ -199,38 +199,60 @@ function () {
|
|
|
199
199
|
return this.buildType(typeNode);
|
|
200
200
|
};
|
|
201
201
|
|
|
202
|
-
_proto.buildDirective = function buildDirective(
|
|
202
|
+
_proto.buildDirective = function buildDirective(directive) {
|
|
203
|
+
var _this = this;
|
|
204
|
+
|
|
205
|
+
var locations = directive.locations.map(function (_ref) {
|
|
206
|
+
var value = _ref.value;
|
|
207
|
+
return value;
|
|
208
|
+
});
|
|
203
209
|
return new GraphQLDirective({
|
|
204
|
-
name:
|
|
205
|
-
description: getDescription(
|
|
206
|
-
locations:
|
|
207
|
-
|
|
210
|
+
name: directive.name.value,
|
|
211
|
+
description: getDescription(directive, this._options),
|
|
212
|
+
locations: locations,
|
|
213
|
+
args: keyByNameNode(directive.arguments || [], function (arg) {
|
|
214
|
+
return _this.buildArg(arg);
|
|
208
215
|
}),
|
|
209
|
-
|
|
210
|
-
astNode: directiveNode
|
|
216
|
+
astNode: directive
|
|
211
217
|
});
|
|
212
218
|
};
|
|
213
219
|
|
|
214
220
|
_proto.buildField = function buildField(field) {
|
|
221
|
+
var _this2 = this;
|
|
222
|
+
|
|
215
223
|
return {
|
|
216
224
|
// Note: While this could make assertions to get the correctly typed
|
|
217
225
|
// value, that would throw immediately while type system validation
|
|
218
226
|
// with validateSchema() will produce more actionable results.
|
|
219
227
|
type: this._buildWrappedType(field.type),
|
|
220
228
|
description: getDescription(field, this._options),
|
|
221
|
-
args: field.arguments
|
|
229
|
+
args: keyByNameNode(field.arguments || [], function (arg) {
|
|
230
|
+
return _this2.buildArg(arg);
|
|
231
|
+
}),
|
|
222
232
|
deprecationReason: getDeprecationReason(field),
|
|
223
233
|
astNode: field
|
|
224
234
|
};
|
|
225
235
|
};
|
|
226
236
|
|
|
237
|
+
_proto.buildArg = function buildArg(value) {
|
|
238
|
+
// Note: While this could make assertions to get the correctly typed
|
|
239
|
+
// value, that would throw immediately while type system validation
|
|
240
|
+
var type = this._buildWrappedType(value.type);
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
type: type,
|
|
244
|
+
description: getDescription(value, this._options),
|
|
245
|
+
defaultValue: valueFromAST(value.defaultValue, type),
|
|
246
|
+
astNode: value
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
|
|
227
250
|
_proto.buildInputField = function buildInputField(value) {
|
|
228
251
|
// Note: While this could make assertions to get the correctly typed
|
|
229
252
|
// value, that would throw immediately while type system validation
|
|
230
253
|
var type = this._buildWrappedType(value.type);
|
|
231
254
|
|
|
232
255
|
return {
|
|
233
|
-
name: value.name.value,
|
|
234
256
|
type: type,
|
|
235
257
|
description: getDescription(value, this._options),
|
|
236
258
|
defaultValue: valueFromAST(value.defaultValue, type),
|
|
@@ -246,129 +268,114 @@ function () {
|
|
|
246
268
|
};
|
|
247
269
|
};
|
|
248
270
|
|
|
249
|
-
_proto._makeSchemaDef = function _makeSchemaDef(
|
|
250
|
-
switch (
|
|
271
|
+
_proto._makeSchemaDef = function _makeSchemaDef(astNode) {
|
|
272
|
+
switch (astNode.kind) {
|
|
251
273
|
case Kind.OBJECT_TYPE_DEFINITION:
|
|
252
|
-
return this._makeTypeDef(
|
|
274
|
+
return this._makeTypeDef(astNode);
|
|
253
275
|
|
|
254
276
|
case Kind.INTERFACE_TYPE_DEFINITION:
|
|
255
|
-
return this._makeInterfaceDef(
|
|
277
|
+
return this._makeInterfaceDef(astNode);
|
|
256
278
|
|
|
257
279
|
case Kind.ENUM_TYPE_DEFINITION:
|
|
258
|
-
return this._makeEnumDef(
|
|
280
|
+
return this._makeEnumDef(astNode);
|
|
259
281
|
|
|
260
282
|
case Kind.UNION_TYPE_DEFINITION:
|
|
261
|
-
return this._makeUnionDef(
|
|
283
|
+
return this._makeUnionDef(astNode);
|
|
262
284
|
|
|
263
285
|
case Kind.SCALAR_TYPE_DEFINITION:
|
|
264
|
-
return this._makeScalarDef(
|
|
286
|
+
return this._makeScalarDef(astNode);
|
|
265
287
|
|
|
266
288
|
case Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
267
|
-
return this._makeInputObjectDef(
|
|
289
|
+
return this._makeInputObjectDef(astNode);
|
|
268
290
|
|
|
269
291
|
default:
|
|
270
|
-
throw new Error("Type kind \"".concat(
|
|
292
|
+
throw new Error("Type kind \"".concat(astNode.kind, "\" not supported."));
|
|
271
293
|
}
|
|
272
294
|
};
|
|
273
295
|
|
|
274
|
-
_proto._makeTypeDef = function _makeTypeDef(
|
|
275
|
-
var _this = this;
|
|
276
|
-
|
|
277
|
-
var interfaces = def.interfaces;
|
|
278
|
-
return new GraphQLObjectType({
|
|
279
|
-
name: def.name.value,
|
|
280
|
-
description: getDescription(def, this._options),
|
|
281
|
-
fields: function fields() {
|
|
282
|
-
return _this._makeFieldDefMap(def);
|
|
283
|
-
},
|
|
284
|
-
// Note: While this could make early assertions to get the correctly
|
|
285
|
-
// typed values, that would throw immediately while type system
|
|
286
|
-
// validation with validateSchema() will produce more actionable results.
|
|
287
|
-
interfaces: interfaces ? function () {
|
|
288
|
-
return interfaces.map(function (ref) {
|
|
289
|
-
return _this.buildType(ref);
|
|
290
|
-
});
|
|
291
|
-
} : [],
|
|
292
|
-
astNode: def
|
|
293
|
-
});
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
_proto._makeFieldDefMap = function _makeFieldDefMap(def) {
|
|
297
|
-
var _this2 = this;
|
|
298
|
-
|
|
299
|
-
return def.fields ? keyValMap(def.fields, function (field) {
|
|
300
|
-
return field.name.value;
|
|
301
|
-
}, function (field) {
|
|
302
|
-
return _this2.buildField(field);
|
|
303
|
-
}) : {};
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
_proto._makeInputValues = function _makeInputValues(values) {
|
|
296
|
+
_proto._makeTypeDef = function _makeTypeDef(astNode) {
|
|
307
297
|
var _this3 = this;
|
|
308
298
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
299
|
+
var interfaceNodes = astNode.interfaces;
|
|
300
|
+
var fieldNodes = astNode.fields; // Note: While this could make assertions to get the correctly typed
|
|
301
|
+
// values below, that would throw immediately while type system
|
|
302
|
+
// validation with validateSchema() will produce more actionable results.
|
|
303
|
+
|
|
304
|
+
var interfaces = interfaceNodes && interfaceNodes.length > 0 ? function () {
|
|
305
|
+
return interfaceNodes.map(function (ref) {
|
|
306
|
+
return _this3.buildType(ref);
|
|
307
|
+
});
|
|
308
|
+
} : [];
|
|
309
|
+
var fields = fieldNodes && fieldNodes.length > 0 ? function () {
|
|
310
|
+
return keyByNameNode(fieldNodes, function (field) {
|
|
311
|
+
return _this3.buildField(field);
|
|
312
|
+
});
|
|
313
|
+
} : Object.create(null);
|
|
314
|
+
return new GraphQLObjectType({
|
|
315
|
+
name: astNode.name.value,
|
|
316
|
+
description: getDescription(astNode, this._options),
|
|
317
|
+
interfaces: interfaces,
|
|
318
|
+
fields: fields,
|
|
319
|
+
astNode: astNode
|
|
313
320
|
});
|
|
314
321
|
};
|
|
315
322
|
|
|
316
|
-
_proto._makeInterfaceDef = function _makeInterfaceDef(
|
|
323
|
+
_proto._makeInterfaceDef = function _makeInterfaceDef(astNode) {
|
|
317
324
|
var _this4 = this;
|
|
318
325
|
|
|
326
|
+
var fieldNodes = astNode.fields;
|
|
327
|
+
var fields = fieldNodes && fieldNodes.length > 0 ? function () {
|
|
328
|
+
return keyByNameNode(fieldNodes, function (field) {
|
|
329
|
+
return _this4.buildField(field);
|
|
330
|
+
});
|
|
331
|
+
} : Object.create(null);
|
|
319
332
|
return new GraphQLInterfaceType({
|
|
320
|
-
name:
|
|
321
|
-
description: getDescription(
|
|
322
|
-
fields:
|
|
323
|
-
|
|
324
|
-
},
|
|
325
|
-
astNode: def
|
|
333
|
+
name: astNode.name.value,
|
|
334
|
+
description: getDescription(astNode, this._options),
|
|
335
|
+
fields: fields,
|
|
336
|
+
astNode: astNode
|
|
326
337
|
});
|
|
327
338
|
};
|
|
328
339
|
|
|
329
|
-
_proto._makeEnumDef = function _makeEnumDef(
|
|
330
|
-
return new GraphQLEnumType({
|
|
331
|
-
name: def.name.value,
|
|
332
|
-
description: getDescription(def, this._options),
|
|
333
|
-
values: this._makeValueDefMap(def),
|
|
334
|
-
astNode: def
|
|
335
|
-
});
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
_proto._makeValueDefMap = function _makeValueDefMap(def) {
|
|
340
|
+
_proto._makeEnumDef = function _makeEnumDef(astNode) {
|
|
339
341
|
var _this5 = this;
|
|
340
342
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
343
|
+
var valueNodes = astNode.values || [];
|
|
344
|
+
return new GraphQLEnumType({
|
|
345
|
+
name: astNode.name.value,
|
|
346
|
+
description: getDescription(astNode, this._options),
|
|
347
|
+
values: keyByNameNode(valueNodes, function (value) {
|
|
348
|
+
return _this5.buildEnumValue(value);
|
|
349
|
+
}),
|
|
350
|
+
astNode: astNode
|
|
351
|
+
});
|
|
346
352
|
};
|
|
347
353
|
|
|
348
|
-
_proto._makeUnionDef = function _makeUnionDef(
|
|
354
|
+
_proto._makeUnionDef = function _makeUnionDef(astNode) {
|
|
349
355
|
var _this6 = this;
|
|
350
356
|
|
|
351
|
-
var
|
|
357
|
+
var typeNodes = astNode.types; // Note: While this could make assertions to get the correctly typed
|
|
358
|
+
// values below, that would throw immediately while type system
|
|
359
|
+
// validation with validateSchema() will produce more actionable results.
|
|
360
|
+
|
|
361
|
+
var types = typeNodes && typeNodes.length > 0 ? function () {
|
|
362
|
+
return typeNodes.map(function (ref) {
|
|
363
|
+
return _this6.buildType(ref);
|
|
364
|
+
});
|
|
365
|
+
} : [];
|
|
352
366
|
return new GraphQLUnionType({
|
|
353
|
-
name:
|
|
354
|
-
description: getDescription(
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
// validation with validateSchema() will produce more actionable results.
|
|
358
|
-
types: types ? function () {
|
|
359
|
-
return types.map(function (ref) {
|
|
360
|
-
return _this6.buildType(ref);
|
|
361
|
-
});
|
|
362
|
-
} : [],
|
|
363
|
-
astNode: def
|
|
367
|
+
name: astNode.name.value,
|
|
368
|
+
description: getDescription(astNode, this._options),
|
|
369
|
+
types: types,
|
|
370
|
+
astNode: astNode
|
|
364
371
|
});
|
|
365
372
|
};
|
|
366
373
|
|
|
367
|
-
_proto._makeScalarDef = function _makeScalarDef(
|
|
374
|
+
_proto._makeScalarDef = function _makeScalarDef(astNode) {
|
|
368
375
|
return new GraphQLScalarType({
|
|
369
|
-
name:
|
|
370
|
-
description: getDescription(
|
|
371
|
-
astNode:
|
|
376
|
+
name: astNode.name.value,
|
|
377
|
+
description: getDescription(astNode, this._options),
|
|
378
|
+
astNode: astNode,
|
|
372
379
|
serialize: function serialize(value) {
|
|
373
380
|
return value;
|
|
374
381
|
}
|
|
@@ -378,23 +385,34 @@ function () {
|
|
|
378
385
|
_proto._makeInputObjectDef = function _makeInputObjectDef(def) {
|
|
379
386
|
var _this7 = this;
|
|
380
387
|
|
|
388
|
+
var fields = def.fields;
|
|
381
389
|
return new GraphQLInputObjectType({
|
|
382
390
|
name: def.name.value,
|
|
383
391
|
description: getDescription(def, this._options),
|
|
384
|
-
fields: function
|
|
385
|
-
return
|
|
386
|
-
|
|
392
|
+
fields: fields ? function () {
|
|
393
|
+
return keyByNameNode(fields, function (field) {
|
|
394
|
+
return _this7.buildInputField(field);
|
|
395
|
+
});
|
|
396
|
+
} : Object.create(null),
|
|
387
397
|
astNode: def
|
|
388
398
|
});
|
|
389
399
|
};
|
|
390
400
|
|
|
391
401
|
return ASTDefinitionBuilder;
|
|
392
402
|
}();
|
|
403
|
+
|
|
404
|
+
function keyByNameNode(list, valFn) {
|
|
405
|
+
return keyValMap(list, function (_ref2) {
|
|
406
|
+
var name = _ref2.name;
|
|
407
|
+
return name.value;
|
|
408
|
+
}, valFn);
|
|
409
|
+
}
|
|
393
410
|
/**
|
|
394
411
|
* Given a field or enum value node, returns the string value for the
|
|
395
412
|
* deprecation reason.
|
|
396
413
|
*/
|
|
397
414
|
|
|
415
|
+
|
|
398
416
|
function getDeprecationReason(node) {
|
|
399
417
|
var deprecated = getDirectiveValues(GraphQLDeprecatedDirective, node);
|
|
400
418
|
return deprecated && deprecated.reason;
|