introspectionFromSchema.js 1.2 KB

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