@graphql-tools/batch-execute 9.0.7 → 9.0.8-alpha-cb1d4231a392ebe0c30e7bf8fa1dafca0e48be48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # @graphql-tools/batch-execute
2
2
 
3
+ ## 9.0.8-alpha-cb1d4231a392ebe0c30e7bf8fa1dafca0e48be48
4
+
5
+ ### Patch Changes
6
+
7
+ - [#243](https://github.com/graphql-hive/gateway/pull/243) [`cb1d423`](https://github.com/graphql-hive/gateway/commit/cb1d4231a392ebe0c30e7bf8fa1dafca0e48be48) Thanks [@ardatan](https://github.com/ardatan)! - Fix the issue that batched query generation when optional variables are not prefixed and sent correctly.
8
+
9
+ See the use case below;
10
+
11
+ When two batched queries are sent like below;
12
+
13
+ ```graphql
14
+ query TestOne($someOptionalVar: String) {
15
+ foo(someOptionalArg: $someOptionalVar) {
16
+ id
17
+ name
18
+ }
19
+ }
20
+ ```
21
+
22
+ ```graphql
23
+ query TestTwo($someOptionalVar: String) {
24
+ foo(someOptionalArg: $someOptionalVar) {
25
+ id
26
+ name
27
+ }
28
+ }
29
+ ```
30
+
31
+ 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.
32
+
33
+ ```graphql
34
+ query TestOneTwo($someOptionalVar: String, $someOptionalVar: String) {
35
+ _0_foo: foo(someOptionalArg: $someOptionalVar) {
36
+ id
37
+ name
38
+ }
39
+ _1_foo: foo(someOptionalArg: $someOptionalVar) {
40
+ id
41
+ name
42
+ }
43
+ }
44
+ ```
45
+
3
46
  ## 9.0.7
4
47
 
5
48
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -111,11 +111,17 @@ function prefixRequest(prefix, request) {
111
111
  }
112
112
  let prefixedDocument = aliasTopLevelFields(prefix, request.document);
113
113
  const executionVariableNames = Object.keys(executionVariables);
114
- const hasFragmentDefinitions = request.document.definitions.some(
115
- (def) => isFragmentDefinition(def)
116
- );
114
+ let hasFragmentDefinitions = false;
115
+ let hasVariables = false;
116
+ for (const def of prefixedDocument.definitions) {
117
+ if (isFragmentDefinition(def)) {
118
+ hasFragmentDefinitions = true;
119
+ } else if (isOperationDefinition(def)) {
120
+ hasVariables = !!def.variableDefinitions?.length;
121
+ }
122
+ }
117
123
  const fragmentSpreadImpl = {};
118
- if (executionVariableNames.length > 0 || hasFragmentDefinitions) {
124
+ if (hasVariables || hasFragmentDefinitions) {
119
125
  prefixedDocument = graphql.visit(prefixedDocument, {
120
126
  [graphql.Kind.VARIABLE]: prefixNode,
121
127
  [graphql.Kind.FRAGMENT_DEFINITION]: prefixNode,
package/dist/index.js CHANGED
@@ -105,11 +105,17 @@ function prefixRequest(prefix, request) {
105
105
  }
106
106
  let prefixedDocument = aliasTopLevelFields(prefix, request.document);
107
107
  const executionVariableNames = Object.keys(executionVariables);
108
- const hasFragmentDefinitions = request.document.definitions.some(
109
- (def) => isFragmentDefinition(def)
110
- );
108
+ let hasFragmentDefinitions = false;
109
+ let hasVariables = false;
110
+ for (const def of prefixedDocument.definitions) {
111
+ if (isFragmentDefinition(def)) {
112
+ hasFragmentDefinitions = true;
113
+ } else if (isOperationDefinition(def)) {
114
+ hasVariables = !!def.variableDefinitions?.length;
115
+ }
116
+ }
111
117
  const fragmentSpreadImpl = {};
112
- if (executionVariableNames.length > 0 || hasFragmentDefinitions) {
118
+ if (hasVariables || hasFragmentDefinitions) {
113
119
  prefixedDocument = visit(prefixedDocument, {
114
120
  [Kind.VARIABLE]: prefixNode,
115
121
  [Kind.FRAGMENT_DEFINITION]: prefixNode,
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@graphql-tools/batch-execute",
3
- "version": "9.0.7",
3
+ "version": "9.0.8-alpha-cb1d4231a392ebe0c30e7bf8fa1dafca0e48be48",
4
4
  "type": "module",
5
5
  "description": "A set of utils for faster development of GraphQL tools",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "graphql-hive/gateway",
8
+ "url": "git+https://github.com/graphql-hive/gateway.git",
9
9
  "directory": "packages/batch-execute"
10
10
  },
11
11
  "license": "MIT",