introspectionFromSchema.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.introspectionFromSchema = introspectionFromSchema;
  6. var _invariant = _interopRequireDefault(require("../jsutils/invariant"));
  7. var _isPromise = _interopRequireDefault(require("../jsutils/isPromise"));
  8. var _parser = require("../language/parser");
  9. var _execute = require("../execution/execute");
  10. var _introspectionQuery = require("./introspectionQuery");
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. /**
  13. * Build an IntrospectionQuery from a GraphQLSchema
  14. *
  15. * IntrospectionQuery is useful for utilities that care about type and field
  16. * relationships, but do not need to traverse through those relationships.
  17. *
  18. * This is the inverse of buildClientSchema. The primary use case is outside
  19. * of the server context, for instance when doing schema comparisons.
  20. */
  21. function introspectionFromSchema(schema, options) {
  22. var queryAST = (0, _parser.parse)((0, _introspectionQuery.getIntrospectionQuery)(options));
  23. var result = (0, _execute.execute)(schema, queryAST);
  24. /* istanbul ignore next */
  25. !(0, _isPromise.default)(result) && !result.errors && result.data || (0, _invariant.default)(0);
  26. return result.data;
  27. }