introspectionFromSchema.mjs 2.0 KB

12345678910111213141516171819202122232425262728293031323334
  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. directiveIsRepeatable: true,
  20. schemaDescription: true
  21. }, options);
  22. var document = parse(getIntrospectionQuery(optionsWithDefaults));
  23. var result = executeSync({
  24. schema: schema,
  25. document: document
  26. });
  27. !result.errors && result.data || invariant(0);
  28. return result.data;
  29. }