UNPKG

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