@graphql-tools/batch-execute
Advanced tools
Comparing version 9.0.7 to 9.0.8-alpha-5fb7ce042dd8c2edbe8ba8947d94342a59270992
# @graphql-tools/batch-execute | ||
## 9.0.8-alpha-5fb7ce042dd8c2edbe8ba8947d94342a59270992 | ||
### Patch Changes | ||
- [#243](https://github.com/graphql-hive/gateway/pull/243) [`5fb7ce0`](https://github.com/graphql-hive/gateway/commit/5fb7ce042dd8c2edbe8ba8947d94342a59270992) Thanks [@ardatan](https://github.com/ardatan)! - Fix the issue that batched query generation when optional variables are not prefixed and sent correctly. | ||
See the use case below; | ||
When two batched queries are sent like below; | ||
```graphql | ||
query TestOne($someOptionalVar: String) { | ||
foo(someOptionalArg: $someOptionalVar) { | ||
id | ||
name | ||
} | ||
} | ||
``` | ||
```graphql | ||
query TestTwo($someOptionalVar: String) { | ||
foo(someOptionalArg: $someOptionalVar) { | ||
id | ||
name | ||
} | ||
} | ||
``` | ||
And then `someOptionalVar` is not prefixed if the value is not sent by the user. The batched queries will be sent as below, then it will cause issues. | ||
```graphql | ||
query TestOneTwo($someOptionalVar: String, $someOptionalVar: String) { | ||
_0_foo: foo(someOptionalArg: $someOptionalVar) { | ||
id | ||
name | ||
} | ||
_1_foo: foo(someOptionalArg: $someOptionalVar) { | ||
id | ||
name | ||
} | ||
} | ||
``` | ||
## 9.0.7 | ||
@@ -4,0 +47,0 @@ |
@@ -108,7 +108,13 @@ import { getOperationASTFromRequest, relocatedError, fakePromise, mapMaybePromise, isAsyncIterable, memoize2of4 } from '@graphql-tools/utils'; | ||
const executionVariableNames = Object.keys(executionVariables); | ||
const hasFragmentDefinitions = request.document.definitions.some( | ||
(def) => isFragmentDefinition(def) | ||
); | ||
let hasFragmentDefinitions = false; | ||
let hasVariables = false; | ||
for (const def of prefixedDocument.definitions) { | ||
if (isFragmentDefinition(def)) { | ||
hasFragmentDefinitions = true; | ||
} else if (isOperationDefinition(def)) { | ||
hasVariables = !!def.variableDefinitions?.length; | ||
} | ||
} | ||
const fragmentSpreadImpl = {}; | ||
if (executionVariableNames.length > 0 || hasFragmentDefinitions) { | ||
if (hasVariables || hasFragmentDefinitions) { | ||
prefixedDocument = visit(prefixedDocument, { | ||
@@ -115,0 +121,0 @@ [Kind.VARIABLE]: prefixNode, |
{ | ||
"name": "@graphql-tools/batch-execute", | ||
"version": "9.0.7", | ||
"version": "9.0.8-alpha-5fb7ce042dd8c2edbe8ba8947d94342a59270992", | ||
"type": "module", | ||
@@ -8,3 +8,3 @@ "description": "A set of utils for faster development of GraphQL tools", | ||
"type": "git", | ||
"url": "graphql-hive/gateway", | ||
"url": "git+https://github.com/graphql-hive/gateway.git", | ||
"directory": "packages/batch-execute" | ||
@@ -11,0 +11,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50398
652
2