UNPKG

2.14 kBJavaScriptView Raw
1function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
2
3function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
5function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
7import invariant from "../jsutils/invariant.mjs";
8import { parse } from "../language/parser.mjs";
9import { executeSync } from "../execution/execute.mjs";
10import { getIntrospectionQuery } from "./getIntrospectionQuery.mjs";
11/**
12 * Build an IntrospectionQuery from a GraphQLSchema
13 *
14 * IntrospectionQuery is useful for utilities that care about type and field
15 * relationships, but do not need to traverse through those relationships.
16 *
17 * This is the inverse of buildClientSchema. The primary use case is outside
18 * of the server context, for instance when doing schema comparisons.
19 */
20
21export function introspectionFromSchema(schema, options) {
22 var optionsWithDefaults = _objectSpread({
23 specifiedByUrl: true,
24 directiveIsRepeatable: true,
25 schemaDescription: true,
26 inputValueDeprecation: true
27 }, options);
28
29 var document = parse(getIntrospectionQuery(optionsWithDefaults));
30 var result = executeSync({
31 schema: schema,
32 document: document
33 });
34 !result.errors && result.data || invariant(0);
35 return result.data;
36}