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AAC,UAAU;QAEpB,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE,CAC7C,MAAM,CAAC,UAAU,CAAC,KAAK,CACrB,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,YAAY,CAAC,IAAI,CACpD,CACF;KACF,CAAC;IAEF,OAAO,IAAI,aAAa,CAAC,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;AACtD,CAAC;AAoCD,MAAM,UAAU,WAAW,CACzB,MAAuB,EACvB,OAA2C;IAE3C,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,EAAE;QAC7B,UAAU,EAAE,OAAO,EAAE,UAAU;QAC/B,6BAA6B,EAAE,OAAO,EAAE,6BAA6B;KACtE,CAAC,CAAC;IAEH,OAAO,cAAc,CAAC,QAAQ,EAAE;QAC9B,cAAc,EAAE,OAAO,EAAE,cAAc;QACvC,WAAW,EAAE,OAAO,EAAE,WAAW;KAClC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/** @category Schema Construction */\n\nimport type { DocumentNode } from '../language/ast.ts';\nimport type { ParseOptions } from '../language/parser.ts';\nimport { parse } from '../language/parser.ts';\nimport type { Source } from '../language/source.ts';\n\nimport { specifiedDirectives } from '../type/directives.ts';\nimport type { GraphQLSchemaValidationOptions } from '../type/schema.ts';\nimport { GraphQLSchema } from '../type/schema.ts';\n\nimport { assertValidSDL } from '../validation/validate.ts';\n\nimport { extendSchemaImpl } from './extendSchema.ts';\n\n/** Options used when building a schema from SDL or a parsed SDL document. */\nexport interface BuildSchemaOptions extends GraphQLSchemaValidationOptions {\n  /**\n   * Set to true to assume the SDL is valid.\n   *\n   * Default: false\n   */\n  assumeValidSDL?: boolean | undefined;\n}\n\n/**\n * Builds a GraphQLSchema from a parsed schema definition language document.\n *\n * If no schema definition is provided, then it will look for types named Query,\n * Mutation and Subscription.\n *\n * The resulting schema has no resolver functions, so execution will use the\n * default field resolver.\n * @param documentAST - The parsed GraphQL document AST.\n * @param options - Optional configuration for this operation.\n * @returns The schema built from the provided SDL document.\n * @example\n * ```ts\n * // Build a schema from a valid parsed SDL document.\n * import { parse } from 'graphql/language';\n * import { buildASTSchema } from 'graphql/utilities';\n *\n * const document = parse('type Query { hello: String }');\n * const schema = buildASTSchema(document);\n *\n * schema.getQueryType().name; // => 'Query'\n * ```\n * @example\n * ```ts\n * // This variant uses validation options when the SDL references unknown types.\n * import { parse } from 'graphql/language';\n * import { buildASTSchema } from 'graphql/utilities';\n *\n * const document = parse('type Query { broken: MissingType }');\n *\n * buildASTSchema(document); // throws an error\n * buildASTSchema(document, {\n *   assumeValid: true,\n *   assumeValidSDL: true,\n * }); // does not throw\n * ```\n */\nexport function buildASTSchema(\n  documentAST: DocumentNode,\n  options?: BuildSchemaOptions,\n): GraphQLSchema {\n  if (options?.assumeValid !== true && options?.assumeValidSDL !== true) {\n    assertValidSDL(documentAST);\n  }\n\n  const emptySchemaConfig = {\n    description: undefined,\n    types: [],\n    directives: [],\n    extensions: Object.create(null),\n    extensionASTNodes: [],\n    assumeValid: false,\n  };\n  const config = extendSchemaImpl(emptySchemaConfig, documentAST, options);\n\n  if (config.astNode == null) {\n    for (const type of config.types) {\n      switch (type.name) {\n        // Note: While this could make early assertions to get the correctly\n        // typed values below, that would throw immediately while type system\n        // validation with validateSchema() will produce more actionable results.\n        case 'Query':\n          // @ts-expect-error validated in `validateSchema`\n          config.query = type;\n          break;\n        case 'Mutation':\n          // @ts-expect-error validated in `validateSchema`\n          config.mutation = type;\n          break;\n        case 'Subscription':\n          // @ts-expect-error validated in `validateSchema`\n          config.subscription = type;\n          break;\n      }\n    }\n  }\n\n  const directives = [\n    ...config.directives,\n    // If specified directives were not explicitly declared, add them.\n    ...specifiedDirectives.filter((stdDirective) =>\n      config.directives.every(\n        (directive) => directive.name !== stdDirective.name,\n      ),\n    ),\n  ];\n\n  return new GraphQLSchema({ ...config, directives });\n}\n\n/**\n * Builds a GraphQLSchema directly from a schema definition language source.\n * @param source - The GraphQL source text or source object.\n * @param options - Optional configuration for this operation.\n * @returns The schema built from the provided SDL document.\n * @example\n * ```ts\n * // Build a schema from SDL source using the default options.\n * import { buildSchema } from 'graphql/utilities';\n *\n * const schema = buildSchema('type Query { hello: String }');\n *\n * schema.getQueryType().name; // => 'Query'\n * ```\n * @example\n * ```ts\n * // This variant enables parser options and omits source locations.\n * import { buildSchema } from 'graphql/utilities';\n *\n * const schema = buildSchema(\n *   'directive @tag on FIELD_DEFINITION\\n' +\n *     'directive @compose @tag on FIELD_DEFINITION',\n *   {\n *     experimentalFragmentArguments: true,\n *     noLocation: true,\n *   },\n * );\n *\n * const directive = schema.getDirective('compose');\n *\n * directive.name; // => 'compose'\n * directive.astNode.loc; // => undefined\n * ```\n */\nexport function buildSchema(\n  source: string | Source,\n  options?: BuildSchemaOptions & ParseOptions,\n): GraphQLSchema {\n  const document = parse(source, {\n    noLocation: options?.noLocation,\n    experimentalFragmentArguments: options?.experimentalFragmentArguments,\n  });\n\n  return buildASTSchema(document, {\n    assumeValidSDL: options?.assumeValidSDL,\n    assumeValid: options?.assumeValid,\n  });\n}\n"]}