Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-tools/batch-execute

Package Overview
Dependencies
Maintainers
4
Versions
700
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/batch-execute - npm Package Compare versions

Comparing version 9.0.7 to 9.0.8-alpha-35bd336e065a644ca50acb0a438bca0609536611

43

CHANGELOG.md
# @graphql-tools/batch-execute
## 9.0.8-alpha-35bd336e065a644ca50acb0a438bca0609536611
### Patch Changes
- [`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.
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 @@

38

dist/index.js

@@ -102,3 +102,2 @@ import { getOperationASTFromRequest, relocatedError, fakePromise, mapMaybePromise, isAsyncIterable, memoize2of4 } from '@graphql-tools/utils';

function prefixRequest(prefix, request) {
const executionVariables = request.variables ?? {};
function prefixNode(node) {

@@ -108,11 +107,18 @@ return prefixNodeName(node, prefix);

let prefixedDocument = aliasTopLevelFields(prefix, request.document);
const executionVariableNames = Object.keys(executionVariables);
const hasFragmentDefinitions = request.document.definitions.some(
(def) => isFragmentDefinition(def)
);
let hasFragmentDefinitionsOrVariables = false;
for (const def of prefixedDocument.definitions) {
if (isFragmentDefinition(def) || isOperationDefinition(def) && !!def.variableDefinitions?.length) {
hasFragmentDefinitionsOrVariables = true;
break;
}
}
const fragmentSpreadImpl = {};
if (executionVariableNames.length > 0 || hasFragmentDefinitions) {
let hasFragments = false;
if (hasFragmentDefinitionsOrVariables) {
prefixedDocument = visit(prefixedDocument, {
[Kind.VARIABLE]: prefixNode,
[Kind.FRAGMENT_DEFINITION]: prefixNode,
[Kind.FRAGMENT_DEFINITION](node) {
hasFragments = true;
return prefixNode(node);
},
[Kind.FRAGMENT_SPREAD]: (node) => {

@@ -125,12 +131,16 @@ node = prefixNodeName(node, prefix);

}
const prefixedVariables = {};
for (const variableName of executionVariableNames) {
prefixedVariables[prefix + variableName] = executionVariables[variableName];
let prefixedVariables;
const executionVariables = request.variables;
if (executionVariables) {
prefixedVariables = /* @__PURE__ */ Object.create(null);
for (const variableName in executionVariables) {
prefixedVariables[prefix + variableName] = executionVariables[variableName];
}
}
if (hasFragmentDefinitions) {
if (hasFragments) {
prefixedDocument = {
...prefixedDocument,
definitions: prefixedDocument.definitions.filter((def) => {
return !isFragmentDefinition(def) || fragmentSpreadImpl[def.name.value];
})
definitions: prefixedDocument.definitions.filter(
(def) => !isFragmentDefinition(def) || fragmentSpreadImpl[def.name.value]
)
};

@@ -137,0 +147,0 @@ }

{
"name": "@graphql-tools/batch-execute",
"version": "9.0.7",
"version": "9.0.8-alpha-35bd336e065a644ca50acb0a438bca0609536611",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc