From 2d7952c3d579b69da5fb8039935d029d08c274dd Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Fri, 27 Jan 2023 10:43:02 -0500 Subject: [PATCH 1/3] feat: update name for graphql batch operations --- .../data-context/src/sources/CloudDataSource.ts | 17 +++++++++++++++-- .../cypress/e2e/e2ePluginSetup.ts | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/data-context/src/sources/CloudDataSource.ts b/packages/data-context/src/sources/CloudDataSource.ts index d8948a91aa86..4621ad7508fd 100644 --- a/packages/data-context/src/sources/CloudDataSource.ts +++ b/packages/data-context/src/sources/CloudDataSource.ts @@ -9,7 +9,7 @@ import crypto from 'crypto' import type { DataContext } from '..' import getenv from 'getenv' -import { print, DocumentNode, ExecutionResult, GraphQLResolveInfo, OperationTypeNode, visit, OperationDefinitionNode } from 'graphql' +import { print, DocumentNode, ExecutionResult, GraphQLResolveInfo, OperationTypeNode, visit, OperationDefinitionNode, FieldNode } from 'graphql' import { createClient, dedupExchange, @@ -402,11 +402,24 @@ function namedExecutionDocument (document: DocumentNode) { } hasReplaced = true + + const selectionSet = new Set() + + op.selectionSet.selections.forEach((selection) => { + selectionSet.add((selection as FieldNode).name.value) + }) + + let operationName = 'batchTestRunnerExecutionQuery' + + if (selectionSet.size > 0) { + operationName = `${operationName}_${Array.from(selectionSet).join('_')}` + } + const namedOperationNode: OperationDefinitionNode = { ...op, name: { kind: 'Name', - value: 'batchTestRunnerExecutionQuery', + value: operationName, }, } diff --git a/packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts b/packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts index 79bd2b333768..87895f4fd502 100644 --- a/packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts +++ b/packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts @@ -239,7 +239,7 @@ async function makeE2ETasks () { operationCount[operationName ?? 'unknown']++ - if (operationName === 'batchTestRunnerExecutionQuery' && remoteGraphQLInterceptBatched) { + if (operationName?.startsWith('batchTestRunnerExecutionQuery') && remoteGraphQLInterceptBatched) { const fn = remoteGraphQLInterceptBatched const keys: string[] = [] const values: Promise[] = [] From 20ed86c71cf8d1ab4abc64246e02940647148ba9 Mon Sep 17 00:00:00 2001 From: estrada9166 Date: Fri, 27 Jan 2023 10:53:41 -0500 Subject: [PATCH 2/3] Validate selection kind --- packages/data-context/src/sources/CloudDataSource.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/data-context/src/sources/CloudDataSource.ts b/packages/data-context/src/sources/CloudDataSource.ts index 4621ad7508fd..2dad6b96ef54 100644 --- a/packages/data-context/src/sources/CloudDataSource.ts +++ b/packages/data-context/src/sources/CloudDataSource.ts @@ -9,7 +9,7 @@ import crypto from 'crypto' import type { DataContext } from '..' import getenv from 'getenv' -import { print, DocumentNode, ExecutionResult, GraphQLResolveInfo, OperationTypeNode, visit, OperationDefinitionNode, FieldNode } from 'graphql' +import { print, DocumentNode, ExecutionResult, GraphQLResolveInfo, OperationTypeNode, visit, OperationDefinitionNode } from 'graphql' import { createClient, dedupExchange, @@ -405,8 +405,10 @@ function namedExecutionDocument (document: DocumentNode) { const selectionSet = new Set() - op.selectionSet.selections.forEach((selection) => { - selectionSet.add((selection as FieldNode).name.value) + op.selectionSet.selections.forEach((s) => { + if (s.kind === 'Field') { + selectionSet.add(s.name.value) + } }) let operationName = 'batchTestRunnerExecutionQuery' From 49b74023b9617c9f6f4ea71f3f53067289ba7991 Mon Sep 17 00:00:00 2001 From: Alejandro Estrada Date: Fri, 27 Jan 2023 10:58:56 -0500 Subject: [PATCH 3/3] Update packages/data-context/src/sources/CloudDataSource.ts Co-authored-by: Tim Griesser --- packages/data-context/src/sources/CloudDataSource.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/data-context/src/sources/CloudDataSource.ts b/packages/data-context/src/sources/CloudDataSource.ts index 2dad6b96ef54..d43bcbab9a3d 100644 --- a/packages/data-context/src/sources/CloudDataSource.ts +++ b/packages/data-context/src/sources/CloudDataSource.ts @@ -414,7 +414,7 @@ function namedExecutionDocument (document: DocumentNode) { let operationName = 'batchTestRunnerExecutionQuery' if (selectionSet.size > 0) { - operationName = `${operationName}_${Array.from(selectionSet).join('_')}` + operationName = `${operationName}_${Array.from(selectionSet).sort().join('_')}` } const namedOperationNode: OperationDefinitionNode = {