UNPKG

21.4 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.isIntrospectionType = isIntrospectionType;
7exports.introspectionTypes = exports.TypeNameMetaFieldDef = exports.TypeMetaFieldDef = exports.SchemaMetaFieldDef = exports.__TypeKind = exports.TypeKind = exports.__EnumValue = exports.__InputValue = exports.__Field = exports.__Type = exports.__DirectiveLocation = exports.__Directive = exports.__Schema = void 0;
8
9var _objectValues = _interopRequireDefault(require("../polyfills/objectValues.js"));
10
11var _inspect = _interopRequireDefault(require("../jsutils/inspect.js"));
12
13var _invariant = _interopRequireDefault(require("../jsutils/invariant.js"));
14
15var _printer = require("../language/printer.js");
16
17var _directiveLocation = require("../language/directiveLocation.js");
18
19var _astFromValue = require("../utilities/astFromValue.js");
20
21var _scalars = require("./scalars.js");
22
23var _definition = require("./definition.js");
24
25function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
27var __Schema = new _definition.GraphQLObjectType({
28 name: '__Schema',
29 description: 'A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations.',
30 fields: function fields() {
31 return {
32 description: {
33 type: _scalars.GraphQLString,
34 resolve: function resolve(schema) {
35 return schema.description;
36 }
37 },
38 types: {
39 description: 'A list of all types supported by this server.',
40 type: new _definition.GraphQLNonNull(new _definition.GraphQLList(new _definition.GraphQLNonNull(__Type))),
41 resolve: function resolve(schema) {
42 return (0, _objectValues.default)(schema.getTypeMap());
43 }
44 },
45 queryType: {
46 description: 'The type that query operations will be rooted at.',
47 type: new _definition.GraphQLNonNull(__Type),
48 resolve: function resolve(schema) {
49 return schema.getQueryType();
50 }
51 },
52 mutationType: {
53 description: 'If this server supports mutation, the type that mutation operations will be rooted at.',
54 type: __Type,
55 resolve: function resolve(schema) {
56 return schema.getMutationType();
57 }
58 },
59 subscriptionType: {
60 description: 'If this server support subscription, the type that subscription operations will be rooted at.',
61 type: __Type,
62 resolve: function resolve(schema) {
63 return schema.getSubscriptionType();
64 }
65 },
66 directives: {
67 description: 'A list of all directives supported by this server.',
68 type: new _definition.GraphQLNonNull(new _definition.GraphQLList(new _definition.GraphQLNonNull(__Directive))),
69 resolve: function resolve(schema) {
70 return schema.getDirectives();
71 }
72 }
73 };
74 }
75});
76
77exports.__Schema = __Schema;
78
79var __Directive = new _definition.GraphQLObjectType({
80 name: '__Directive',
81 description: "A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.\n\nIn some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.",
82 fields: function fields() {
83 return {
84 name: {
85 type: new _definition.GraphQLNonNull(_scalars.GraphQLString),
86 resolve: function resolve(directive) {
87 return directive.name;
88 }
89 },
90 description: {
91 type: _scalars.GraphQLString,
92 resolve: function resolve(directive) {
93 return directive.description;
94 }
95 },
96 isRepeatable: {
97 type: new _definition.GraphQLNonNull(_scalars.GraphQLBoolean),
98 resolve: function resolve(directive) {
99 return directive.isRepeatable;
100 }
101 },
102 locations: {
103 type: new _definition.GraphQLNonNull(new _definition.GraphQLList(new _definition.GraphQLNonNull(__DirectiveLocation))),
104 resolve: function resolve(directive) {
105 return directive.locations;
106 }
107 },
108 args: {
109 type: new _definition.GraphQLNonNull(new _definition.GraphQLList(new _definition.GraphQLNonNull(__InputValue))),
110 resolve: function resolve(directive) {
111 return directive.args;
112 }
113 }
114 };
115 }
116});
117
118exports.__Directive = __Directive;
119
120var __DirectiveLocation = new _definition.GraphQLEnumType({
121 name: '__DirectiveLocation',
122 description: 'A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.',
123 values: {
124 QUERY: {
125 value: _directiveLocation.DirectiveLocation.QUERY,
126 description: 'Location adjacent to a query operation.'
127 },
128 MUTATION: {
129 value: _directiveLocation.DirectiveLocation.MUTATION,
130 description: 'Location adjacent to a mutation operation.'
131 },
132 SUBSCRIPTION: {
133 value: _directiveLocation.DirectiveLocation.SUBSCRIPTION,
134 description: 'Location adjacent to a subscription operation.'
135 },
136 FIELD: {
137 value: _directiveLocation.DirectiveLocation.FIELD,
138 description: 'Location adjacent to a field.'
139 },
140 FRAGMENT_DEFINITION: {
141 value: _directiveLocation.DirectiveLocation.FRAGMENT_DEFINITION,
142 description: 'Location adjacent to a fragment definition.'
143 },
144 FRAGMENT_SPREAD: {
145 value: _directiveLocation.DirectiveLocation.FRAGMENT_SPREAD,
146 description: 'Location adjacent to a fragment spread.'
147 },
148 INLINE_FRAGMENT: {
149 value: _directiveLocation.DirectiveLocation.INLINE_FRAGMENT,
150 description: 'Location adjacent to an inline fragment.'
151 },
152 VARIABLE_DEFINITION: {
153 value: _directiveLocation.DirectiveLocation.VARIABLE_DEFINITION,
154 description: 'Location adjacent to a variable definition.'
155 },
156 SCHEMA: {
157 value: _directiveLocation.DirectiveLocation.SCHEMA,
158 description: 'Location adjacent to a schema definition.'
159 },
160 SCALAR: {
161 value: _directiveLocation.DirectiveLocation.SCALAR,
162 description: 'Location adjacent to a scalar definition.'
163 },
164 OBJECT: {
165 value: _directiveLocation.DirectiveLocation.OBJECT,
166 description: 'Location adjacent to an object type definition.'
167 },
168 FIELD_DEFINITION: {
169 value: _directiveLocation.DirectiveLocation.FIELD_DEFINITION,
170 description: 'Location adjacent to a field definition.'
171 },
172 ARGUMENT_DEFINITION: {
173 value: _directiveLocation.DirectiveLocation.ARGUMENT_DEFINITION,
174 description: 'Location adjacent to an argument definition.'
175 },
176 INTERFACE: {
177 value: _directiveLocation.DirectiveLocation.INTERFACE,
178 description: 'Location adjacent to an interface definition.'
179 },
180 UNION: {
181 value: _directiveLocation.DirectiveLocation.UNION,
182 description: 'Location adjacent to a union definition.'
183 },
184 ENUM: {
185 value: _directiveLocation.DirectiveLocation.ENUM,
186 description: 'Location adjacent to an enum definition.'
187 },
188 ENUM_VALUE: {
189 value: _directiveLocation.DirectiveLocation.ENUM_VALUE,
190 description: 'Location adjacent to an enum value definition.'
191 },
192 INPUT_OBJECT: {
193 value: _directiveLocation.DirectiveLocation.INPUT_OBJECT,
194 description: 'Location adjacent to an input object type definition.'
195 },
196 INPUT_FIELD_DEFINITION: {
197 value: _directiveLocation.DirectiveLocation.INPUT_FIELD_DEFINITION,
198 description: 'Location adjacent to an input object field definition.'
199 }
200 }
201});
202
203exports.__DirectiveLocation = __DirectiveLocation;
204
205var __Type = new _definition.GraphQLObjectType({
206 name: '__Type',
207 description: 'The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.\n\nDepending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name, description and optional `specifiedByUrl`, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.',
208 fields: function fields() {
209 return {
210 kind: {
211 type: new _definition.GraphQLNonNull(__TypeKind),
212 resolve: function resolve(type) {
213 if ((0, _definition.isScalarType)(type)) {
214 return TypeKind.SCALAR;
215 }
216
217 if ((0, _definition.isObjectType)(type)) {
218 return TypeKind.OBJECT;
219 }
220
221 if ((0, _definition.isInterfaceType)(type)) {
222 return TypeKind.INTERFACE;
223 }
224
225 if ((0, _definition.isUnionType)(type)) {
226 return TypeKind.UNION;
227 }
228
229 if ((0, _definition.isEnumType)(type)) {
230 return TypeKind.ENUM;
231 }
232
233 if ((0, _definition.isInputObjectType)(type)) {
234 return TypeKind.INPUT_OBJECT;
235 }
236
237 if ((0, _definition.isListType)(type)) {
238 return TypeKind.LIST;
239 } // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2618')
240
241
242 if ((0, _definition.isNonNullType)(type)) {
243 return TypeKind.NON_NULL;
244 } // istanbul ignore next (Not reachable. All possible types have been considered)
245
246
247 false || (0, _invariant.default)(0, "Unexpected type: \"".concat((0, _inspect.default)(type), "\"."));
248 }
249 },
250 name: {
251 type: _scalars.GraphQLString,
252 resolve: function resolve(type) {
253 return type.name !== undefined ? type.name : undefined;
254 }
255 },
256 description: {
257 type: _scalars.GraphQLString,
258 resolve: function resolve(type) {
259 return type.description !== undefined ? type.description : undefined;
260 }
261 },
262 specifiedByUrl: {
263 type: _scalars.GraphQLString,
264 resolve: function resolve(obj) {
265 return obj.specifiedByUrl !== undefined ? obj.specifiedByUrl : undefined;
266 }
267 },
268 fields: {
269 type: new _definition.GraphQLList(new _definition.GraphQLNonNull(__Field)),
270 args: {
271 includeDeprecated: {
272 type: _scalars.GraphQLBoolean,
273 defaultValue: false
274 }
275 },
276 resolve: function resolve(type, _ref) {
277 var includeDeprecated = _ref.includeDeprecated;
278
279 if ((0, _definition.isObjectType)(type) || (0, _definition.isInterfaceType)(type)) {
280 var fields = (0, _objectValues.default)(type.getFields());
281 return includeDeprecated ? fields : fields.filter(function (field) {
282 return field.deprecationReason == null;
283 });
284 }
285 }
286 },
287 interfaces: {
288 type: new _definition.GraphQLList(new _definition.GraphQLNonNull(__Type)),
289 resolve: function resolve(type) {
290 if ((0, _definition.isObjectType)(type) || (0, _definition.isInterfaceType)(type)) {
291 return type.getInterfaces();
292 }
293 }
294 },
295 possibleTypes: {
296 type: new _definition.GraphQLList(new _definition.GraphQLNonNull(__Type)),
297 resolve: function resolve(type, _args, _context, _ref2) {
298 var schema = _ref2.schema;
299
300 if ((0, _definition.isAbstractType)(type)) {
301 return schema.getPossibleTypes(type);
302 }
303 }
304 },
305 enumValues: {
306 type: new _definition.GraphQLList(new _definition.GraphQLNonNull(__EnumValue)),
307 args: {
308 includeDeprecated: {
309 type: _scalars.GraphQLBoolean,
310 defaultValue: false
311 }
312 },
313 resolve: function resolve(type, _ref3) {
314 var includeDeprecated = _ref3.includeDeprecated;
315
316 if ((0, _definition.isEnumType)(type)) {
317 var values = type.getValues();
318 return includeDeprecated ? values : values.filter(function (field) {
319 return field.deprecationReason == null;
320 });
321 }
322 }
323 },
324 inputFields: {
325 type: new _definition.GraphQLList(new _definition.GraphQLNonNull(__InputValue)),
326 args: {
327 includeDeprecated: {
328 type: _scalars.GraphQLBoolean,
329 defaultValue: false
330 }
331 },
332 resolve: function resolve(type, _ref4) {
333 var includeDeprecated = _ref4.includeDeprecated;
334
335 if ((0, _definition.isInputObjectType)(type)) {
336 var values = (0, _objectValues.default)(type.getFields());
337 return includeDeprecated ? values : values.filter(function (field) {
338 return field.deprecationReason == null;
339 });
340 }
341 }
342 },
343 ofType: {
344 type: __Type,
345 resolve: function resolve(type) {
346 return type.ofType !== undefined ? type.ofType : undefined;
347 }
348 }
349 };
350 }
351});
352
353exports.__Type = __Type;
354
355var __Field = new _definition.GraphQLObjectType({
356 name: '__Field',
357 description: 'Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.',
358 fields: function fields() {
359 return {
360 name: {
361 type: new _definition.GraphQLNonNull(_scalars.GraphQLString),
362 resolve: function resolve(field) {
363 return field.name;
364 }
365 },
366 description: {
367 type: _scalars.GraphQLString,
368 resolve: function resolve(field) {
369 return field.description;
370 }
371 },
372 args: {
373 type: new _definition.GraphQLNonNull(new _definition.GraphQLList(new _definition.GraphQLNonNull(__InputValue))),
374 args: {
375 includeDeprecated: {
376 type: _scalars.GraphQLBoolean,
377 defaultValue: false
378 }
379 },
380 resolve: function resolve(field, _ref5) {
381 var includeDeprecated = _ref5.includeDeprecated;
382 return includeDeprecated ? field.args : field.args.filter(function (arg) {
383 return arg.deprecationReason == null;
384 });
385 }
386 },
387 type: {
388 type: new _definition.GraphQLNonNull(__Type),
389 resolve: function resolve(field) {
390 return field.type;
391 }
392 },
393 isDeprecated: {
394 type: new _definition.GraphQLNonNull(_scalars.GraphQLBoolean),
395 resolve: function resolve(field) {
396 return field.deprecationReason != null;
397 }
398 },
399 deprecationReason: {
400 type: _scalars.GraphQLString,
401 resolve: function resolve(field) {
402 return field.deprecationReason;
403 }
404 }
405 };
406 }
407});
408
409exports.__Field = __Field;
410
411var __InputValue = new _definition.GraphQLObjectType({
412 name: '__InputValue',
413 description: 'Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value.',
414 fields: function fields() {
415 return {
416 name: {
417 type: new _definition.GraphQLNonNull(_scalars.GraphQLString),
418 resolve: function resolve(inputValue) {
419 return inputValue.name;
420 }
421 },
422 description: {
423 type: _scalars.GraphQLString,
424 resolve: function resolve(inputValue) {
425 return inputValue.description;
426 }
427 },
428 type: {
429 type: new _definition.GraphQLNonNull(__Type),
430 resolve: function resolve(inputValue) {
431 return inputValue.type;
432 }
433 },
434 defaultValue: {
435 type: _scalars.GraphQLString,
436 description: 'A GraphQL-formatted string representing the default value for this input value.',
437 resolve: function resolve(inputValue) {
438 var type = inputValue.type,
439 defaultValue = inputValue.defaultValue;
440 var valueAST = (0, _astFromValue.astFromValue)(defaultValue, type);
441 return valueAST ? (0, _printer.print)(valueAST) : null;
442 }
443 },
444 isDeprecated: {
445 type: new _definition.GraphQLNonNull(_scalars.GraphQLBoolean),
446 resolve: function resolve(field) {
447 return field.deprecationReason != null;
448 }
449 },
450 deprecationReason: {
451 type: _scalars.GraphQLString,
452 resolve: function resolve(obj) {
453 return obj.deprecationReason;
454 }
455 }
456 };
457 }
458});
459
460exports.__InputValue = __InputValue;
461
462var __EnumValue = new _definition.GraphQLObjectType({
463 name: '__EnumValue',
464 description: 'One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string.',
465 fields: function fields() {
466 return {
467 name: {
468 type: new _definition.GraphQLNonNull(_scalars.GraphQLString),
469 resolve: function resolve(enumValue) {
470 return enumValue.name;
471 }
472 },
473 description: {
474 type: _scalars.GraphQLString,
475 resolve: function resolve(enumValue) {
476 return enumValue.description;
477 }
478 },
479 isDeprecated: {
480 type: new _definition.GraphQLNonNull(_scalars.GraphQLBoolean),
481 resolve: function resolve(enumValue) {
482 return enumValue.deprecationReason != null;
483 }
484 },
485 deprecationReason: {
486 type: _scalars.GraphQLString,
487 resolve: function resolve(enumValue) {
488 return enumValue.deprecationReason;
489 }
490 }
491 };
492 }
493});
494
495exports.__EnumValue = __EnumValue;
496var TypeKind = Object.freeze({
497 SCALAR: 'SCALAR',
498 OBJECT: 'OBJECT',
499 INTERFACE: 'INTERFACE',
500 UNION: 'UNION',
501 ENUM: 'ENUM',
502 INPUT_OBJECT: 'INPUT_OBJECT',
503 LIST: 'LIST',
504 NON_NULL: 'NON_NULL'
505});
506exports.TypeKind = TypeKind;
507
508var __TypeKind = new _definition.GraphQLEnumType({
509 name: '__TypeKind',
510 description: 'An enum describing what kind of type a given `__Type` is.',
511 values: {
512 SCALAR: {
513 value: TypeKind.SCALAR,
514 description: 'Indicates this type is a scalar.'
515 },
516 OBJECT: {
517 value: TypeKind.OBJECT,
518 description: 'Indicates this type is an object. `fields` and `interfaces` are valid fields.'
519 },
520 INTERFACE: {
521 value: TypeKind.INTERFACE,
522 description: 'Indicates this type is an interface. `fields`, `interfaces`, and `possibleTypes` are valid fields.'
523 },
524 UNION: {
525 value: TypeKind.UNION,
526 description: 'Indicates this type is a union. `possibleTypes` is a valid field.'
527 },
528 ENUM: {
529 value: TypeKind.ENUM,
530 description: 'Indicates this type is an enum. `enumValues` is a valid field.'
531 },
532 INPUT_OBJECT: {
533 value: TypeKind.INPUT_OBJECT,
534 description: 'Indicates this type is an input object. `inputFields` is a valid field.'
535 },
536 LIST: {
537 value: TypeKind.LIST,
538 description: 'Indicates this type is a list. `ofType` is a valid field.'
539 },
540 NON_NULL: {
541 value: TypeKind.NON_NULL,
542 description: 'Indicates this type is a non-null. `ofType` is a valid field.'
543 }
544 }
545});
546/**
547 * Note that these are GraphQLField and not GraphQLFieldConfig,
548 * so the format for args is different.
549 */
550
551
552exports.__TypeKind = __TypeKind;
553var SchemaMetaFieldDef = {
554 name: '__schema',
555 type: new _definition.GraphQLNonNull(__Schema),
556 description: 'Access the current type schema of this server.',
557 args: [],
558 resolve: function resolve(_source, _args, _context, _ref6) {
559 var schema = _ref6.schema;
560 return schema;
561 },
562 isDeprecated: false,
563 deprecationReason: undefined,
564 extensions: undefined,
565 astNode: undefined
566};
567exports.SchemaMetaFieldDef = SchemaMetaFieldDef;
568var TypeMetaFieldDef = {
569 name: '__type',
570 type: __Type,
571 description: 'Request the type information of a single type.',
572 args: [{
573 name: 'name',
574 description: undefined,
575 type: new _definition.GraphQLNonNull(_scalars.GraphQLString),
576 defaultValue: undefined,
577 deprecationReason: undefined,
578 extensions: undefined,
579 astNode: undefined
580 }],
581 resolve: function resolve(_source, _ref7, _context, _ref8) {
582 var name = _ref7.name;
583 var schema = _ref8.schema;
584 return schema.getType(name);
585 },
586 isDeprecated: false,
587 deprecationReason: undefined,
588 extensions: undefined,
589 astNode: undefined
590};
591exports.TypeMetaFieldDef = TypeMetaFieldDef;
592var TypeNameMetaFieldDef = {
593 name: '__typename',
594 type: new _definition.GraphQLNonNull(_scalars.GraphQLString),
595 description: 'The name of the current Object type at runtime.',
596 args: [],
597 resolve: function resolve(_source, _args, _context, _ref9) {
598 var parentType = _ref9.parentType;
599 return parentType.name;
600 },
601 isDeprecated: false,
602 deprecationReason: undefined,
603 extensions: undefined,
604 astNode: undefined
605};
606exports.TypeNameMetaFieldDef = TypeNameMetaFieldDef;
607var introspectionTypes = Object.freeze([__Schema, __Directive, __DirectiveLocation, __Type, __Field, __InputValue, __EnumValue, __TypeKind]);
608exports.introspectionTypes = introspectionTypes;
609
610function isIntrospectionType(type) {
611 return introspectionTypes.some(function (_ref10) {
612 var name = _ref10.name;
613 return type.name === name;
614 });
615}