Skip to content

Commit

Permalink
Make queryPlanStoreKey a hash of both the query and operationName (
Browse files Browse the repository at this point in the history
  • Loading branch information
AneethAnand authored Feb 24, 2023
1 parent 72253b0 commit ccbf459
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .changeset/fluffy-toes-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@apollo/gateway": patch
---

Previously the `queryPlanStoreKey` was a hash of the query concatenated with an unhashed `operationName` if it was present. This resulted in variable length cache keys that could become unnecessarily long, occupying additional space in the query plan cache.

This change incorporates the `operationName` _into_ the hash itself (if `operationName` is present).

6 changes: 4 additions & 2 deletions gateway-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Logger } from '@apollo/utils.logger';
import LRUCache from 'lru-cache';
import {
GraphQLSchema,
VariableDefinitionNode,
VariableDefinitionNode
} from 'graphql';
import { buildOperationContext, OperationContext } from './operationContext';
import {
Expand Down Expand Up @@ -750,7 +750,9 @@ export class ApolloGateway implements GatewayInterface {
async (span) => {
try {
const { request, document, queryHash } = requestContext;
const queryPlanStoreKey = queryHash + (request.operationName || '');
const queryPlanStoreKey = request.operationName ?
createHash('sha256').update(queryHash).update(request.operationName).digest('hex')
: queryHash;
const operationContext = buildOperationContext({
schema: this.schema!,
operationDocument: document,
Expand Down

0 comments on commit ccbf459

Please sign in to comment.