UNPKG

1.25 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true,
5});
6exports.introspectionFromSchema = introspectionFromSchema;
7
8var _invariant = require('../jsutils/invariant.js');
9
10var _parser = require('../language/parser.js');
11
12var _execute = require('../execution/execute.js');
13
14var _getIntrospectionQuery = require('./getIntrospectionQuery.js');
15
16/**
17 * Build an IntrospectionQuery from a GraphQLSchema
18 *
19 * IntrospectionQuery is useful for utilities that care about type and field
20 * relationships, but do not need to traverse through those relationships.
21 *
22 * This is the inverse of buildClientSchema. The primary use case is outside
23 * of the server context, for instance when doing schema comparisons.
24 */
25function introspectionFromSchema(schema, options) {
26 const optionsWithDefaults = {
27 specifiedByUrl: true,
28 directiveIsRepeatable: true,
29 schemaDescription: true,
30 inputValueDeprecation: true,
31 ...options,
32 };
33 const document = (0, _parser.parse)(
34 (0, _getIntrospectionQuery.getIntrospectionQuery)(optionsWithDefaults),
35 );
36 const result = (0, _execute.executeSync)({
37 schema,
38 document,
39 });
40 (!result.errors && result.data) || (0, _invariant.invariant)(false);
41 return result.data;
42}