UNPKG

894 BJavaScriptView Raw
1import invariant from '../jsutils/invariant';
2import isPromise from '../jsutils/isPromise';
3import { parse } from '../language/parser';
4import { execute } from '../execution/execute';
5import { getIntrospectionQuery } from './introspectionQuery';
6/**
7 * Build an IntrospectionQuery from a GraphQLSchema
8 *
9 * IntrospectionQuery is useful for utilities that care about type and field
10 * relationships, but do not need to traverse through those relationships.
11 *
12 * This is the inverse of buildClientSchema. The primary use case is outside
13 * of the server context, for instance when doing schema comparisons.
14 */
15
16export function introspectionFromSchema(schema, options) {
17 var queryAST = parse(getIntrospectionQuery(options));
18 var result = execute(schema, queryAST);
19
20 /* istanbul ignore next */
21 !isPromise(result) && !result.errors && result.data || invariant(0);
22 return result.data;
23}