UNPKG

graphql

Version:

A Query Language and Runtime which can target any service.

1 lines 1.52 kB
{"version":3,"file":"concatAST.js","sourceRoot":"","sources":["../../src/utilities/concatAST.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,8BAA6B;AAqB5C,MAAM,UAAU,SAAS,CACvB,SAAsC;IAEtC,MAAM,WAAW,GAA0B,EAAE,CAAC;IAC9C,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;QAC5B,WAAW,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,CAAC;AAC9C,CAAC","sourcesContent":["/** @category AST Utilities */\n\nimport type { DefinitionNode, DocumentNode } from '../language/ast.ts';\nimport { Kind } from '../language/kinds.ts';\n\n/**\n * Provided a collection of ASTs, presumably each from different files,\n * concatenate the ASTs together into batched AST, useful for validating many\n * GraphQL source files which together represent one conceptual application.\n * @param documents - Document ASTs to concatenate.\n * @returns A document AST containing all definitions from the provided documents.\n * @example\n * ```ts\n * import { parse } from 'graphql/language';\n * import { concatAST } from 'graphql/utilities';\n *\n * const document = concatAST([\n * parse('type Query { a: String }'),\n * parse('type User { id: ID }'),\n * ]);\n *\n * document.definitions.length; // => 2\n * ```\n */\nexport function concatAST(\n documents: ReadonlyArray<DocumentNode>,\n): DocumentNode {\n const definitions: Array<DefinitionNode> = [];\n for (const doc of documents) {\n definitions.push(...doc.definitions);\n }\n return { kind: Kind.DOCUMENT, definitions };\n}\n"]}