introspectionFromSchema.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.introspectionFromSchema = introspectionFromSchema;
  6. var _invariant = _interopRequireDefault(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. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. function 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; }
  12. function _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; }
  13. function _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; }
  14. /**
  15. * Build an IntrospectionQuery from a GraphQLSchema
  16. *
  17. * IntrospectionQuery is useful for utilities that care about type and field
  18. * relationships, but do not need to traverse through those relationships.
  19. *
  20. * This is the inverse of buildClientSchema. The primary use case is outside
  21. * of the server context, for instance when doing schema comparisons.
  22. */
  23. function introspectionFromSchema(schema, options) {
  24. var optionsWithDefaults = _objectSpread({
  25. specifiedByUrl: true,
  26. directiveIsRepeatable: true,
  27. schemaDescription: true,
  28. inputValueDeprecation: true
  29. }, options);
  30. var document = (0, _parser.parse)((0, _getIntrospectionQuery.getIntrospectionQuery)(optionsWithDefaults));
  31. var result = (0, _execute.executeSync)({
  32. schema: schema,
  33. document: document
  34. });
  35. !result.errors && result.data || (0, _invariant.default)(0);
  36. return result.data;
  37. }