UNPKG

1.39 kBTypeScriptView Raw
1import { ExecutionRequest } from '@graphql-tools/utils';
2/**
3 * Merge multiple queries into a single query in such a way that query results
4 * can be split and transformed as if they were obtained by running original queries.
5 *
6 * Merging algorithm involves several transformations:
7 * 1. Replace top-level fragment spreads with inline fragments (... on Query {})
8 * 2. Add unique aliases to all top-level query fields (including those on inline fragments)
9 * 3. Prefix all variable definitions and variable usages
10 * 4. Prefix names (and spreads) of fragments
11 *
12 * i.e transform:
13 * [
14 * `query Foo($id: ID!) { foo, bar(id: $id), ...FooQuery }
15 * fragment FooQuery on Query { baz }`,
16 *
17 * `query Bar($id: ID!) { foo: baz, bar(id: $id), ... on Query { baz } }`
18 * ]
19 * to:
20 * query (
21 * $graphqlTools1_id: ID!
22 * $graphqlTools2_id: ID!
23 * ) {
24 * graphqlTools1_foo: foo,
25 * graphqlTools1_bar: bar(id: $graphqlTools1_id)
26 * ... on Query {
27 * graphqlTools1__baz: baz
28 * }
29 * graphqlTools1__foo: baz
30 * graphqlTools1__bar: bar(id: $graphqlTools1__id)
31 * ... on Query {
32 * graphqlTools1__baz: baz
33 * }
34 * }
35 */
36export declare function mergeRequests(requests: Array<ExecutionRequest>, extensionsReducer: (mergedExtensions: Record<string, any>, request: ExecutionRequest) => Record<string, any>): ExecutionRequest;