introspectionFromSchema.mjs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 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; }
  2. 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; }
  3. 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; }
  4. import invariant from "../jsutils/invariant.mjs";
  5. import { parse } from "../language/parser.mjs";
  6. import { executeSync } from "../execution/execute.mjs";
  7. import { getIntrospectionQuery } from "./getIntrospectionQuery.mjs";
  8. /**
  9. * Build an IntrospectionQuery from a GraphQLSchema
  10. *
  11. * IntrospectionQuery is useful for utilities that care about type and field
  12. * relationships, but do not need to traverse through those relationships.
  13. *
  14. * This is the inverse of buildClientSchema. The primary use case is outside
  15. * of the server context, for instance when doing schema comparisons.
  16. */
  17. export function introspectionFromSchema(schema, options) {
  18. var optionsWithDefaults = _objectSpread({
  19. specifiedByUrl: true,
  20. directiveIsRepeatable: true,
  21. schemaDescription: true,
  22. inputValueDeprecation: true
  23. }, options);
  24. var document = parse(getIntrospectionQuery(optionsWithDefaults));
  25. var result = executeSync({
  26. schema: schema,
  27. document: document
  28. });
  29. !result.errors && result.data || invariant(0);
  30. return result.data;
  31. }