|
1 | 1 | import { buildSubgraphSchema } from '@apollo/subgraph';
|
2 | 2 | import { normalizedExecutor } from '@graphql-tools/executor';
|
3 |
| -import { parse } from 'graphql'; |
4 |
| -import { describe, expect, it } from 'vitest'; |
| 3 | +import { ExecutionRequest } from '@graphql-tools/utils'; |
| 4 | +import { ExecutionResult, parse } from 'graphql'; |
| 5 | +import { describe, expect, it, vi } from 'vitest'; |
5 | 6 | import { getStitchedSchemaFromLocalSchemas } from './getStitchedSchemaFromLocalSchemas';
|
6 | 7 |
|
7 |
| -describe('Aliased Shared Root Fields', () => { |
8 |
| - it('issue #6613', async () => { |
| 8 | +describe('Shared Root Fields', () => { |
| 9 | + it('Aliased shared root fields issue #6613', async () => { |
9 | 10 | const query = /* GraphQL */ `
|
10 | 11 | query {
|
11 | 12 | testNestedField {
|
@@ -109,4 +110,76 @@ describe('Aliased Shared Root Fields', () => {
|
109 | 110 |
|
110 | 111 | expect(result).toEqual(expectedResult);
|
111 | 112 | });
|
| 113 | + it('Mutations should not be batched', async () => { |
| 114 | + const SUBGRAPHA = buildSubgraphSchema({ |
| 115 | + typeDefs: parse(/* GraphQL */ ` |
| 116 | + type Query { |
| 117 | + test: String |
| 118 | + } |
| 119 | +
|
| 120 | + type Mutation { |
| 121 | + testMutation: String |
| 122 | + } |
| 123 | + `), |
| 124 | + resolvers: { |
| 125 | + Query: { |
| 126 | + test: () => 'test', |
| 127 | + }, |
| 128 | + Mutation: { |
| 129 | + testMutation: () => 'testMutation', |
| 130 | + }, |
| 131 | + }, |
| 132 | + }); |
| 133 | + const SUBGRAPHB = buildSubgraphSchema({ |
| 134 | + typeDefs: parse(/* GraphQL */ ` |
| 135 | + type Query { |
| 136 | + test: String |
| 137 | + } |
| 138 | +
|
| 139 | + type Mutation { |
| 140 | + testMutation: String |
| 141 | + } |
| 142 | + `), |
| 143 | + resolvers: { |
| 144 | + Query: { |
| 145 | + test: () => 'test', |
| 146 | + }, |
| 147 | + Mutation: { |
| 148 | + testMutation: () => 'testMutation', |
| 149 | + }, |
| 150 | + }, |
| 151 | + }); |
| 152 | + const onSubgraphExecuteFn = |
| 153 | + vi.fn< |
| 154 | + ( |
| 155 | + subgraph: string, |
| 156 | + executionRequest: ExecutionRequest, |
| 157 | + result: ExecutionResult | AsyncIterable<ExecutionResult>, |
| 158 | + ) => void |
| 159 | + >(); |
| 160 | + const gatewaySchema = await getStitchedSchemaFromLocalSchemas( |
| 161 | + { |
| 162 | + SUBGRAPHA, |
| 163 | + SUBGRAPHB, |
| 164 | + }, |
| 165 | + onSubgraphExecuteFn, |
| 166 | + ); |
| 167 | + |
| 168 | + const result = await normalizedExecutor({ |
| 169 | + schema: gatewaySchema, |
| 170 | + document: parse(/* GraphQL */ ` |
| 171 | + mutation { |
| 172 | + testMutation |
| 173 | + } |
| 174 | + `), |
| 175 | + }); |
| 176 | + |
| 177 | + expect(result).toEqual({ |
| 178 | + data: { |
| 179 | + testMutation: 'testMutation', |
| 180 | + }, |
| 181 | + }); |
| 182 | + |
| 183 | + expect(onSubgraphExecuteFn).toHaveBeenCalledTimes(1); |
| 184 | + }); |
112 | 185 | });
|
0 commit comments