introspectionFromSchema.mjs 894 B

1234567891011121314151617181920212223
  1. import invariant from '../jsutils/invariant';
  2. import isPromise from '../jsutils/isPromise';
  3. import { parse } from '../language/parser';
  4. import { execute } from '../execution/execute';
  5. import { 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. export function introspectionFromSchema(schema, options) {
  16. var queryAST = parse(getIntrospectionQuery(options));
  17. var result = execute(schema, queryAST);
  18. /* istanbul ignore next */
  19. !isPromise(result) && !result.errors && result.data || invariant(0);
  20. return result.data;
  21. }