extendSchema.mjs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. import { devAssert } from '../jsutils/devAssert.mjs';
  2. import { inspect } from '../jsutils/inspect.mjs';
  3. import { invariant } from '../jsutils/invariant.mjs';
  4. import { keyMap } from '../jsutils/keyMap.mjs';
  5. import { mapValue } from '../jsutils/mapValue.mjs';
  6. import { Kind } from '../language/kinds.mjs';
  7. import {
  8. isTypeDefinitionNode,
  9. isTypeExtensionNode,
  10. } from '../language/predicates.mjs';
  11. import {
  12. GraphQLEnumType,
  13. GraphQLInputObjectType,
  14. GraphQLInterfaceType,
  15. GraphQLList,
  16. GraphQLNonNull,
  17. GraphQLObjectType,
  18. GraphQLScalarType,
  19. GraphQLUnionType,
  20. isEnumType,
  21. isInputObjectType,
  22. isInterfaceType,
  23. isListType,
  24. isNonNullType,
  25. isObjectType,
  26. isScalarType,
  27. isUnionType,
  28. } from '../type/definition.mjs';
  29. import {
  30. GraphQLDeprecatedDirective,
  31. GraphQLDirective,
  32. GraphQLSpecifiedByDirective,
  33. } from '../type/directives.mjs';
  34. import {
  35. introspectionTypes,
  36. isIntrospectionType,
  37. } from '../type/introspection.mjs';
  38. import {
  39. isSpecifiedScalarType,
  40. specifiedScalarTypes,
  41. } from '../type/scalars.mjs';
  42. import { assertSchema, GraphQLSchema } from '../type/schema.mjs';
  43. import { assertValidSDLExtension } from '../validation/validate.mjs';
  44. import { getDirectiveValues } from '../execution/values.mjs';
  45. import { valueFromAST } from './valueFromAST.mjs';
  46. /**
  47. * Produces a new schema given an existing schema and a document which may
  48. * contain GraphQL type extensions and definitions. The original schema will
  49. * remain unaltered.
  50. *
  51. * Because a schema represents a graph of references, a schema cannot be
  52. * extended without effectively making an entire copy. We do not know until it's
  53. * too late if subgraphs remain unchanged.
  54. *
  55. * This algorithm copies the provided schema, applying extensions while
  56. * producing the copy. The original schema remains unaltered.
  57. */
  58. export function extendSchema(schema, documentAST, options) {
  59. assertSchema(schema);
  60. (documentAST != null && documentAST.kind === Kind.DOCUMENT) ||
  61. devAssert(false, 'Must provide valid Document AST.');
  62. if (
  63. (options === null || options === void 0 ? void 0 : options.assumeValid) !==
  64. true &&
  65. (options === null || options === void 0
  66. ? void 0
  67. : options.assumeValidSDL) !== true
  68. ) {
  69. assertValidSDLExtension(documentAST, schema);
  70. }
  71. const schemaConfig = schema.toConfig();
  72. const extendedConfig = extendSchemaImpl(schemaConfig, documentAST, options);
  73. return schemaConfig === extendedConfig
  74. ? schema
  75. : new GraphQLSchema(extendedConfig);
  76. }
  77. /**
  78. * @internal
  79. */
  80. export function extendSchemaImpl(schemaConfig, documentAST, options) {
  81. var _schemaDef, _schemaDef$descriptio, _schemaDef2, _options$assumeValid;
  82. // Collect the type definitions and extensions found in the document.
  83. const typeDefs = [];
  84. const typeExtensionsMap = Object.create(null); // New directives and types are separate because a directives and types can
  85. // have the same name. For example, a type named "skip".
  86. const directiveDefs = [];
  87. let schemaDef; // Schema extensions are collected which may add additional operation types.
  88. const schemaExtensions = [];
  89. for (const def of documentAST.definitions) {
  90. if (def.kind === Kind.SCHEMA_DEFINITION) {
  91. schemaDef = def;
  92. } else if (def.kind === Kind.SCHEMA_EXTENSION) {
  93. schemaExtensions.push(def);
  94. } else if (isTypeDefinitionNode(def)) {
  95. typeDefs.push(def);
  96. } else if (isTypeExtensionNode(def)) {
  97. const extendedTypeName = def.name.value;
  98. const existingTypeExtensions = typeExtensionsMap[extendedTypeName];
  99. typeExtensionsMap[extendedTypeName] = existingTypeExtensions
  100. ? existingTypeExtensions.concat([def])
  101. : [def];
  102. } else if (def.kind === Kind.DIRECTIVE_DEFINITION) {
  103. directiveDefs.push(def);
  104. }
  105. } // If this document contains no new types, extensions, or directives then
  106. // return the same unmodified GraphQLSchema instance.
  107. if (
  108. Object.keys(typeExtensionsMap).length === 0 &&
  109. typeDefs.length === 0 &&
  110. directiveDefs.length === 0 &&
  111. schemaExtensions.length === 0 &&
  112. schemaDef == null
  113. ) {
  114. return schemaConfig;
  115. }
  116. const typeMap = Object.create(null);
  117. for (const existingType of schemaConfig.types) {
  118. typeMap[existingType.name] = extendNamedType(existingType);
  119. }
  120. for (const typeNode of typeDefs) {
  121. var _stdTypeMap$name;
  122. const name = typeNode.name.value;
  123. typeMap[name] =
  124. (_stdTypeMap$name = stdTypeMap[name]) !== null &&
  125. _stdTypeMap$name !== void 0
  126. ? _stdTypeMap$name
  127. : buildType(typeNode);
  128. }
  129. const operationTypes = {
  130. // Get the extended root operation types.
  131. query: schemaConfig.query && replaceNamedType(schemaConfig.query),
  132. mutation: schemaConfig.mutation && replaceNamedType(schemaConfig.mutation),
  133. subscription:
  134. schemaConfig.subscription && replaceNamedType(schemaConfig.subscription),
  135. // Then, incorporate schema definition and all schema extensions.
  136. ...(schemaDef && getOperationTypes([schemaDef])),
  137. ...getOperationTypes(schemaExtensions),
  138. }; // Then produce and return a Schema config with these types.
  139. return {
  140. description:
  141. (_schemaDef = schemaDef) === null || _schemaDef === void 0
  142. ? void 0
  143. : (_schemaDef$descriptio = _schemaDef.description) === null ||
  144. _schemaDef$descriptio === void 0
  145. ? void 0
  146. : _schemaDef$descriptio.value,
  147. ...operationTypes,
  148. types: Object.values(typeMap),
  149. directives: [
  150. ...schemaConfig.directives.map(replaceDirective),
  151. ...directiveDefs.map(buildDirective),
  152. ],
  153. extensions: Object.create(null),
  154. astNode:
  155. (_schemaDef2 = schemaDef) !== null && _schemaDef2 !== void 0
  156. ? _schemaDef2
  157. : schemaConfig.astNode,
  158. extensionASTNodes: schemaConfig.extensionASTNodes.concat(schemaExtensions),
  159. assumeValid:
  160. (_options$assumeValid =
  161. options === null || options === void 0
  162. ? void 0
  163. : options.assumeValid) !== null && _options$assumeValid !== void 0
  164. ? _options$assumeValid
  165. : false,
  166. }; // Below are functions used for producing this schema that have closed over
  167. // this scope and have access to the schema, cache, and newly defined types.
  168. function replaceType(type) {
  169. if (isListType(type)) {
  170. // @ts-expect-error
  171. return new GraphQLList(replaceType(type.ofType));
  172. }
  173. if (isNonNullType(type)) {
  174. // @ts-expect-error
  175. return new GraphQLNonNull(replaceType(type.ofType));
  176. } // @ts-expect-error FIXME
  177. return replaceNamedType(type);
  178. }
  179. function replaceNamedType(type) {
  180. // Note: While this could make early assertions to get the correctly
  181. // typed values, that would throw immediately while type system
  182. // validation with validateSchema() will produce more actionable results.
  183. return typeMap[type.name];
  184. }
  185. function replaceDirective(directive) {
  186. const config = directive.toConfig();
  187. return new GraphQLDirective({
  188. ...config,
  189. args: mapValue(config.args, extendArg),
  190. });
  191. }
  192. function extendNamedType(type) {
  193. if (isIntrospectionType(type) || isSpecifiedScalarType(type)) {
  194. // Builtin types are not extended.
  195. return type;
  196. }
  197. if (isScalarType(type)) {
  198. return extendScalarType(type);
  199. }
  200. if (isObjectType(type)) {
  201. return extendObjectType(type);
  202. }
  203. if (isInterfaceType(type)) {
  204. return extendInterfaceType(type);
  205. }
  206. if (isUnionType(type)) {
  207. return extendUnionType(type);
  208. }
  209. if (isEnumType(type)) {
  210. return extendEnumType(type);
  211. }
  212. if (isInputObjectType(type)) {
  213. return extendInputObjectType(type);
  214. }
  215. /* c8 ignore next 3 */
  216. // Not reachable, all possible type definition nodes have been considered.
  217. false || invariant(false, 'Unexpected type: ' + inspect(type));
  218. }
  219. function extendInputObjectType(type) {
  220. var _typeExtensionsMap$co;
  221. const config = type.toConfig();
  222. const extensions =
  223. (_typeExtensionsMap$co = typeExtensionsMap[config.name]) !== null &&
  224. _typeExtensionsMap$co !== void 0
  225. ? _typeExtensionsMap$co
  226. : [];
  227. return new GraphQLInputObjectType({
  228. ...config,
  229. fields: () => ({
  230. ...mapValue(config.fields, (field) => ({
  231. ...field,
  232. type: replaceType(field.type),
  233. })),
  234. ...buildInputFieldMap(extensions),
  235. }),
  236. extensionASTNodes: config.extensionASTNodes.concat(extensions),
  237. });
  238. }
  239. function extendEnumType(type) {
  240. var _typeExtensionsMap$ty;
  241. const config = type.toConfig();
  242. const extensions =
  243. (_typeExtensionsMap$ty = typeExtensionsMap[type.name]) !== null &&
  244. _typeExtensionsMap$ty !== void 0
  245. ? _typeExtensionsMap$ty
  246. : [];
  247. return new GraphQLEnumType({
  248. ...config,
  249. values: { ...config.values, ...buildEnumValueMap(extensions) },
  250. extensionASTNodes: config.extensionASTNodes.concat(extensions),
  251. });
  252. }
  253. function extendScalarType(type) {
  254. var _typeExtensionsMap$co2;
  255. const config = type.toConfig();
  256. const extensions =
  257. (_typeExtensionsMap$co2 = typeExtensionsMap[config.name]) !== null &&
  258. _typeExtensionsMap$co2 !== void 0
  259. ? _typeExtensionsMap$co2
  260. : [];
  261. let specifiedByURL = config.specifiedByURL;
  262. for (const extensionNode of extensions) {
  263. var _getSpecifiedByURL;
  264. specifiedByURL =
  265. (_getSpecifiedByURL = getSpecifiedByURL(extensionNode)) !== null &&
  266. _getSpecifiedByURL !== void 0
  267. ? _getSpecifiedByURL
  268. : specifiedByURL;
  269. }
  270. return new GraphQLScalarType({
  271. ...config,
  272. specifiedByURL,
  273. extensionASTNodes: config.extensionASTNodes.concat(extensions),
  274. });
  275. }
  276. function extendObjectType(type) {
  277. var _typeExtensionsMap$co3;
  278. const config = type.toConfig();
  279. const extensions =
  280. (_typeExtensionsMap$co3 = typeExtensionsMap[config.name]) !== null &&
  281. _typeExtensionsMap$co3 !== void 0
  282. ? _typeExtensionsMap$co3
  283. : [];
  284. return new GraphQLObjectType({
  285. ...config,
  286. interfaces: () => [
  287. ...type.getInterfaces().map(replaceNamedType),
  288. ...buildInterfaces(extensions),
  289. ],
  290. fields: () => ({
  291. ...mapValue(config.fields, extendField),
  292. ...buildFieldMap(extensions),
  293. }),
  294. extensionASTNodes: config.extensionASTNodes.concat(extensions),
  295. });
  296. }
  297. function extendInterfaceType(type) {
  298. var _typeExtensionsMap$co4;
  299. const config = type.toConfig();
  300. const extensions =
  301. (_typeExtensionsMap$co4 = typeExtensionsMap[config.name]) !== null &&
  302. _typeExtensionsMap$co4 !== void 0
  303. ? _typeExtensionsMap$co4
  304. : [];
  305. return new GraphQLInterfaceType({
  306. ...config,
  307. interfaces: () => [
  308. ...type.getInterfaces().map(replaceNamedType),
  309. ...buildInterfaces(extensions),
  310. ],
  311. fields: () => ({
  312. ...mapValue(config.fields, extendField),
  313. ...buildFieldMap(extensions),
  314. }),
  315. extensionASTNodes: config.extensionASTNodes.concat(extensions),
  316. });
  317. }
  318. function extendUnionType(type) {
  319. var _typeExtensionsMap$co5;
  320. const config = type.toConfig();
  321. const extensions =
  322. (_typeExtensionsMap$co5 = typeExtensionsMap[config.name]) !== null &&
  323. _typeExtensionsMap$co5 !== void 0
  324. ? _typeExtensionsMap$co5
  325. : [];
  326. return new GraphQLUnionType({
  327. ...config,
  328. types: () => [
  329. ...type.getTypes().map(replaceNamedType),
  330. ...buildUnionTypes(extensions),
  331. ],
  332. extensionASTNodes: config.extensionASTNodes.concat(extensions),
  333. });
  334. }
  335. function extendField(field) {
  336. return {
  337. ...field,
  338. type: replaceType(field.type),
  339. args: field.args && mapValue(field.args, extendArg),
  340. };
  341. }
  342. function extendArg(arg) {
  343. return { ...arg, type: replaceType(arg.type) };
  344. }
  345. function getOperationTypes(nodes) {
  346. const opTypes = {};
  347. for (const node of nodes) {
  348. var _node$operationTypes;
  349. // FIXME: https://github.com/graphql/graphql-js/issues/2203
  350. const operationTypesNodes =
  351. /* c8 ignore next */
  352. (_node$operationTypes = node.operationTypes) !== null &&
  353. _node$operationTypes !== void 0
  354. ? _node$operationTypes
  355. : [];
  356. for (const operationType of operationTypesNodes) {
  357. // Note: While this could make early assertions to get the correctly
  358. // typed values below, that would throw immediately while type system
  359. // validation with validateSchema() will produce more actionable results.
  360. // @ts-expect-error
  361. opTypes[operationType.operation] = getNamedType(operationType.type);
  362. }
  363. }
  364. return opTypes;
  365. }
  366. function getNamedType(node) {
  367. var _stdTypeMap$name2;
  368. const name = node.name.value;
  369. const type =
  370. (_stdTypeMap$name2 = stdTypeMap[name]) !== null &&
  371. _stdTypeMap$name2 !== void 0
  372. ? _stdTypeMap$name2
  373. : typeMap[name];
  374. if (type === undefined) {
  375. throw new Error(`Unknown type: "${name}".`);
  376. }
  377. return type;
  378. }
  379. function getWrappedType(node) {
  380. if (node.kind === Kind.LIST_TYPE) {
  381. return new GraphQLList(getWrappedType(node.type));
  382. }
  383. if (node.kind === Kind.NON_NULL_TYPE) {
  384. return new GraphQLNonNull(getWrappedType(node.type));
  385. }
  386. return getNamedType(node);
  387. }
  388. function buildDirective(node) {
  389. var _node$description;
  390. return new GraphQLDirective({
  391. name: node.name.value,
  392. description:
  393. (_node$description = node.description) === null ||
  394. _node$description === void 0
  395. ? void 0
  396. : _node$description.value,
  397. // @ts-expect-error
  398. locations: node.locations.map(({ value }) => value),
  399. isRepeatable: node.repeatable,
  400. args: buildArgumentMap(node.arguments),
  401. astNode: node,
  402. });
  403. }
  404. function buildFieldMap(nodes) {
  405. const fieldConfigMap = Object.create(null);
  406. for (const node of nodes) {
  407. var _node$fields;
  408. // FIXME: https://github.com/graphql/graphql-js/issues/2203
  409. const nodeFields =
  410. /* c8 ignore next */
  411. (_node$fields = node.fields) !== null && _node$fields !== void 0
  412. ? _node$fields
  413. : [];
  414. for (const field of nodeFields) {
  415. var _field$description;
  416. fieldConfigMap[field.name.value] = {
  417. // Note: While this could make assertions to get the correctly typed
  418. // value, that would throw immediately while type system validation
  419. // with validateSchema() will produce more actionable results.
  420. type: getWrappedType(field.type),
  421. description:
  422. (_field$description = field.description) === null ||
  423. _field$description === void 0
  424. ? void 0
  425. : _field$description.value,
  426. args: buildArgumentMap(field.arguments),
  427. deprecationReason: getDeprecationReason(field),
  428. astNode: field,
  429. };
  430. }
  431. }
  432. return fieldConfigMap;
  433. }
  434. function buildArgumentMap(args) {
  435. // FIXME: https://github.com/graphql/graphql-js/issues/2203
  436. const argsNodes =
  437. /* c8 ignore next */
  438. args !== null && args !== void 0 ? args : [];
  439. const argConfigMap = Object.create(null);
  440. for (const arg of argsNodes) {
  441. var _arg$description;
  442. // Note: While this could make assertions to get the correctly typed
  443. // value, that would throw immediately while type system validation
  444. // with validateSchema() will produce more actionable results.
  445. const type = getWrappedType(arg.type);
  446. argConfigMap[arg.name.value] = {
  447. type,
  448. description:
  449. (_arg$description = arg.description) === null ||
  450. _arg$description === void 0
  451. ? void 0
  452. : _arg$description.value,
  453. defaultValue: valueFromAST(arg.defaultValue, type),
  454. deprecationReason: getDeprecationReason(arg),
  455. astNode: arg,
  456. };
  457. }
  458. return argConfigMap;
  459. }
  460. function buildInputFieldMap(nodes) {
  461. const inputFieldMap = Object.create(null);
  462. for (const node of nodes) {
  463. var _node$fields2;
  464. // FIXME: https://github.com/graphql/graphql-js/issues/2203
  465. const fieldsNodes =
  466. /* c8 ignore next */
  467. (_node$fields2 = node.fields) !== null && _node$fields2 !== void 0
  468. ? _node$fields2
  469. : [];
  470. for (const field of fieldsNodes) {
  471. var _field$description2;
  472. // Note: While this could make assertions to get the correctly typed
  473. // value, that would throw immediately while type system validation
  474. // with validateSchema() will produce more actionable results.
  475. const type = getWrappedType(field.type);
  476. inputFieldMap[field.name.value] = {
  477. type,
  478. description:
  479. (_field$description2 = field.description) === null ||
  480. _field$description2 === void 0
  481. ? void 0
  482. : _field$description2.value,
  483. defaultValue: valueFromAST(field.defaultValue, type),
  484. deprecationReason: getDeprecationReason(field),
  485. astNode: field,
  486. };
  487. }
  488. }
  489. return inputFieldMap;
  490. }
  491. function buildEnumValueMap(nodes) {
  492. const enumValueMap = Object.create(null);
  493. for (const node of nodes) {
  494. var _node$values;
  495. // FIXME: https://github.com/graphql/graphql-js/issues/2203
  496. const valuesNodes =
  497. /* c8 ignore next */
  498. (_node$values = node.values) !== null && _node$values !== void 0
  499. ? _node$values
  500. : [];
  501. for (const value of valuesNodes) {
  502. var _value$description;
  503. enumValueMap[value.name.value] = {
  504. description:
  505. (_value$description = value.description) === null ||
  506. _value$description === void 0
  507. ? void 0
  508. : _value$description.value,
  509. deprecationReason: getDeprecationReason(value),
  510. astNode: value,
  511. };
  512. }
  513. }
  514. return enumValueMap;
  515. }
  516. function buildInterfaces(nodes) {
  517. // Note: While this could make assertions to get the correctly typed
  518. // values below, that would throw immediately while type system
  519. // validation with validateSchema() will produce more actionable results.
  520. // @ts-expect-error
  521. return nodes.flatMap(
  522. // FIXME: https://github.com/graphql/graphql-js/issues/2203
  523. (node) => {
  524. var _node$interfaces$map, _node$interfaces;
  525. return (
  526. /* c8 ignore next */
  527. (_node$interfaces$map =
  528. (_node$interfaces = node.interfaces) === null ||
  529. _node$interfaces === void 0
  530. ? void 0
  531. : _node$interfaces.map(getNamedType)) !== null &&
  532. _node$interfaces$map !== void 0
  533. ? _node$interfaces$map
  534. : []
  535. );
  536. },
  537. );
  538. }
  539. function buildUnionTypes(nodes) {
  540. // Note: While this could make assertions to get the correctly typed
  541. // values below, that would throw immediately while type system
  542. // validation with validateSchema() will produce more actionable results.
  543. // @ts-expect-error
  544. return nodes.flatMap(
  545. // FIXME: https://github.com/graphql/graphql-js/issues/2203
  546. (node) => {
  547. var _node$types$map, _node$types;
  548. return (
  549. /* c8 ignore next */
  550. (_node$types$map =
  551. (_node$types = node.types) === null || _node$types === void 0
  552. ? void 0
  553. : _node$types.map(getNamedType)) !== null &&
  554. _node$types$map !== void 0
  555. ? _node$types$map
  556. : []
  557. );
  558. },
  559. );
  560. }
  561. function buildType(astNode) {
  562. var _typeExtensionsMap$na;
  563. const name = astNode.name.value;
  564. const extensionASTNodes =
  565. (_typeExtensionsMap$na = typeExtensionsMap[name]) !== null &&
  566. _typeExtensionsMap$na !== void 0
  567. ? _typeExtensionsMap$na
  568. : [];
  569. switch (astNode.kind) {
  570. case Kind.OBJECT_TYPE_DEFINITION: {
  571. var _astNode$description;
  572. const allNodes = [astNode, ...extensionASTNodes];
  573. return new GraphQLObjectType({
  574. name,
  575. description:
  576. (_astNode$description = astNode.description) === null ||
  577. _astNode$description === void 0
  578. ? void 0
  579. : _astNode$description.value,
  580. interfaces: () => buildInterfaces(allNodes),
  581. fields: () => buildFieldMap(allNodes),
  582. astNode,
  583. extensionASTNodes,
  584. });
  585. }
  586. case Kind.INTERFACE_TYPE_DEFINITION: {
  587. var _astNode$description2;
  588. const allNodes = [astNode, ...extensionASTNodes];
  589. return new GraphQLInterfaceType({
  590. name,
  591. description:
  592. (_astNode$description2 = astNode.description) === null ||
  593. _astNode$description2 === void 0
  594. ? void 0
  595. : _astNode$description2.value,
  596. interfaces: () => buildInterfaces(allNodes),
  597. fields: () => buildFieldMap(allNodes),
  598. astNode,
  599. extensionASTNodes,
  600. });
  601. }
  602. case Kind.ENUM_TYPE_DEFINITION: {
  603. var _astNode$description3;
  604. const allNodes = [astNode, ...extensionASTNodes];
  605. return new GraphQLEnumType({
  606. name,
  607. description:
  608. (_astNode$description3 = astNode.description) === null ||
  609. _astNode$description3 === void 0
  610. ? void 0
  611. : _astNode$description3.value,
  612. values: buildEnumValueMap(allNodes),
  613. astNode,
  614. extensionASTNodes,
  615. });
  616. }
  617. case Kind.UNION_TYPE_DEFINITION: {
  618. var _astNode$description4;
  619. const allNodes = [astNode, ...extensionASTNodes];
  620. return new GraphQLUnionType({
  621. name,
  622. description:
  623. (_astNode$description4 = astNode.description) === null ||
  624. _astNode$description4 === void 0
  625. ? void 0
  626. : _astNode$description4.value,
  627. types: () => buildUnionTypes(allNodes),
  628. astNode,
  629. extensionASTNodes,
  630. });
  631. }
  632. case Kind.SCALAR_TYPE_DEFINITION: {
  633. var _astNode$description5;
  634. return new GraphQLScalarType({
  635. name,
  636. description:
  637. (_astNode$description5 = astNode.description) === null ||
  638. _astNode$description5 === void 0
  639. ? void 0
  640. : _astNode$description5.value,
  641. specifiedByURL: getSpecifiedByURL(astNode),
  642. astNode,
  643. extensionASTNodes,
  644. });
  645. }
  646. case Kind.INPUT_OBJECT_TYPE_DEFINITION: {
  647. var _astNode$description6;
  648. const allNodes = [astNode, ...extensionASTNodes];
  649. return new GraphQLInputObjectType({
  650. name,
  651. description:
  652. (_astNode$description6 = astNode.description) === null ||
  653. _astNode$description6 === void 0
  654. ? void 0
  655. : _astNode$description6.value,
  656. fields: () => buildInputFieldMap(allNodes),
  657. astNode,
  658. extensionASTNodes,
  659. });
  660. }
  661. }
  662. }
  663. }
  664. const stdTypeMap = keyMap(
  665. [...specifiedScalarTypes, ...introspectionTypes],
  666. (type) => type.name,
  667. );
  668. /**
  669. * Given a field or enum value node, returns the string value for the
  670. * deprecation reason.
  671. */
  672. function getDeprecationReason(node) {
  673. const deprecated = getDirectiveValues(GraphQLDeprecatedDirective, node); // @ts-expect-error validated by `getDirectiveValues`
  674. return deprecated === null || deprecated === void 0
  675. ? void 0
  676. : deprecated.reason;
  677. }
  678. /**
  679. * Given a scalar node, returns the string value for the specifiedByURL.
  680. */
  681. function getSpecifiedByURL(node) {
  682. const specifiedBy = getDirectiveValues(GraphQLSpecifiedByDirective, node); // @ts-expect-error validated by `getDirectiveValues`
  683. return specifiedBy === null || specifiedBy === void 0
  684. ? void 0
  685. : specifiedBy.url;
  686. }