UNPKG

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