extendSchema.js 24 KB

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