UNPKG

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