{"version":3,"file":"introspectionFromSchema.js","sourceRoot":"","sources":["../../src/utilities/introspectionFromSchema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,iCAAgC;AAEpD,OAAO,EAAE,KAAK,EAAE,+BAA8B;AAI9C,OAAO,EAAE,WAAW,EAAE,iCAAgC;AAMtD,OAAO,EAAE,qBAAqB,EAAE,oCAAmC;AAoEnE,MAAM,UAAU,uBAAuB,CACrC,MAAqB,EACrB,OAA8B;IAE9B,MAAM,mBAAmB,GAAG;QAC1B,cAAc,EAAE,IAAI;QACpB,qBAAqB,EAAE,IAAI;QAC3B,iBAAiB,EAAE,IAAI;QACvB,qBAAqB,EAAE,IAAI;QAC3B,gCAAgC,EAAE,IAAI;QACtC,KAAK,EAAE,IAAI;QACX,GAAG,OAAO;KACX,CAAC;IAEF,MAAM,QAAQ,GAAG,KAAK,CAAC,qBAAqB,CAAC,mBAAmB,CAAC,CAAC,CAAC;IACnE,MAAM,MAAM,GAAG,WAAW,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;UACvC,MAAM,CAAC,MAAM,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,IAAI,IAAI;QAAtD,SAAS;IACT,OAAO,MAAM,CAAC,IAAW,CAAC;AAC5B,CAAC","sourcesContent":["/** @category Introspection */\n\nimport { invariant } from '../jsutils/invariant.ts';\n\nimport { parse } from '../language/parser.ts';\n\nimport type { GraphQLSchema } from '../type/schema.ts';\n\nimport { executeSync } from '../execution/execute.ts';\n\nimport type {\n  IntrospectionOptions,\n  IntrospectionQuery,\n} from './getIntrospectionQuery.ts';\nimport { getIntrospectionQuery } from './getIntrospectionQuery.ts';\n\n/**\n * Build an IntrospectionQuery from a GraphQLSchema\n *\n * IntrospectionQuery is useful for utilities that care about type and field\n * relationships, but do not need to traverse through those relationships.\n *\n * This is the inverse of buildClientSchema. The primary use case is outside\n * of the server context, for instance when doing schema comparisons.\n * @param schema - GraphQL schema to use.\n * @param options - Optional configuration for this operation.\n * @returns Introspection result data for the schema.\n * @example\n * ```ts\n * // Include schema metadata using the default introspection options.\n * import { buildSchema, introspectionFromSchema } from 'graphql/utilities';\n *\n * const schema = buildSchema(`\n *   scalar Url @specifiedBy(url: \"https://url.spec.whatwg.org/\")\n *\n *   type Query {\n *     homepage: Url\n *   }\n * `);\n *\n * const introspection = introspectionFromSchema(schema);\n * const urlType = introspection.__schema.types.find(\n *   (type) => type.name === 'Url',\n * );\n *\n * urlType.specifiedByURL; // => 'https://url.spec.whatwg.org/'\n * ```\n * @example\n * ```ts\n * // This variant disables optional introspection metadata.\n * import { buildSchema, introspectionFromSchema } from 'graphql/utilities';\n *\n * const schema = buildSchema(`\n *   scalar Url @specifiedBy(url: \"https://url.spec.whatwg.org/\")\n *\n *   type Query {\n *     homepage: Url\n *   }\n * `);\n *\n * const introspection = introspectionFromSchema(schema, {\n *   descriptions: false,\n *   specifiedByUrl: false,\n *   directiveIsRepeatable: false,\n *   schemaDescription: false,\n *   inputValueDeprecation: false,\n *   experimentalDirectiveDeprecation: false,\n *   oneOf: false,\n * });\n * const urlType = introspection.__schema.types.find(\n *   (type) => type.name === 'Url',\n * );\n * const deprecatedDirective = introspection.__schema.directives.find(\n *   (directive) => directive.name === 'deprecated',\n * );\n *\n * urlType.specifiedByURL; // => undefined\n * urlType.description; // => undefined\n * introspection.__schema.description; // => undefined\n * deprecatedDirective.isRepeatable; // => undefined\n * ```\n */\nexport function introspectionFromSchema(\n  schema: GraphQLSchema,\n  options?: IntrospectionOptions,\n): IntrospectionQuery {\n  const optionsWithDefaults = {\n    specifiedByUrl: true,\n    directiveIsRepeatable: true,\n    schemaDescription: true,\n    inputValueDeprecation: true,\n    experimentalDirectiveDeprecation: true,\n    oneOf: true,\n    ...options,\n  };\n\n  const document = parse(getIntrospectionQuery(optionsWithDefaults));\n  const result = executeSync({ schema, document });\n  invariant(result.errors == null && result.data != null);\n  return result.data as any;\n}\n"]}