Skip to content

Commit

Permalink
properly set the operation kind in FetchNode
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoffroy Couprie committed Feb 10, 2022
1 parent b6edfb6 commit 0e6e535
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions query-planner-js/src/buildPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import {
terminateWithNonRequestedTypenameField,
getLocallySatisfiableKey,
} from "@apollo/query-graphs";
import { DocumentNode, OperationDefinitionNode, stripIgnoredCharacters, print, GraphQLError, parse } from "graphql";
import { stripIgnoredCharacters, print, GraphQLError, parse, OperationTypeNode } from "graphql";
import { QueryPlan, ResponsePath, SequenceNode, PlanNode, ParallelNode, FetchNode, trimSelectionNodes } from "./QueryPlan";

const debug = newDebugLogger('plan');
Expand Down Expand Up @@ -800,8 +800,8 @@ class FetchGroup {
serviceName: this.subgraphName,
requires: inputNodes ? trimSelectionNodes(inputNodes.selections) : undefined,
variableUsages: this.selection.usedVariables().map(v => v.name),
operation: stripIgnoredCharacters(print(operation)),
operationKind: (operation.definitions[0] as OperationDefinitionNode).operation,
operation: stripIgnoredCharacters(print(operationToDocument(operation))),
operationKind: operation.rootKind as OperationTypeNode,
};

return this.isTopLevel
Expand Down Expand Up @@ -1672,7 +1672,7 @@ function operationForEntitiesFetch(
selectionSet: SelectionSet,
allVariableDefinitions: VariableDefinitions,
fragments?: NamedFragments
): DocumentNode {
): Operation {
const variableDefinitions = new VariableDefinitions();
variableDefinitions.add(representationsVariableDefinition(subgraphSchema));
variableDefinitions.addAll(allVariableDefinitions.filter(selectionSet.usedVariables()));
Expand All @@ -1689,7 +1689,7 @@ function operationForEntitiesFetch(
selectionSet
));

return operationToDocument(new Operation('query', entitiesCall, variableDefinitions).optimize(fragments));
return new Operation('query', entitiesCall, variableDefinitions).optimize(fragments);
}

// Wraps the given nodes in a ParallelNode or SequenceNode, unless there's only
Expand All @@ -1716,7 +1716,6 @@ function operationForQueryFetch(
selectionSet: SelectionSet,
allVariableDefinitions: VariableDefinitions,
fragments?: NamedFragments
): DocumentNode {
const operation = new Operation(rootKind, selectionSet, allVariableDefinitions.filter(selectionSet.usedVariables())).optimize(fragments);
return operationToDocument(operation);
): Operation {
return new Operation(rootKind, selectionSet, allVariableDefinitions.filter(selectionSet.usedVariables())).optimize(fragments);
}

0 comments on commit 0e6e535

Please sign in to comment.