UNPKG

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