@apollo/gateway 2.3.4 → 2.4.0-alpha.1

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/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { deprecate } from 'util';
2
2
  import { createHash } from '@apollo/utils.createhash';
3
3
  import type { Logger } from '@apollo/utils.logger';
4
- import LRUCache from 'lru-cache';
4
+ import { QueryPlanCache } from '@apollo/query-planner'
5
+ import { InMemoryLRUCache } from '@apollo/utils.keyvaluecache';
5
6
  import {
6
7
  GraphQLSchema,
7
8
  VariableDefinitionNode
@@ -123,7 +124,7 @@ export class ApolloGateway implements GatewayInterface {
123
124
  private serviceMap: DataSourceMap = Object.create(null);
124
125
  private config: GatewayConfig;
125
126
  private logger: Logger;
126
- private queryPlanStore: LRUCache<string, QueryPlan>;
127
+ private queryPlanStore: QueryPlanCache;
127
128
  private apolloConfig?: ApolloConfigFromAS3;
128
129
  private onSchemaChangeListeners = new Set<(schema: GraphQLSchema) => void>();
129
130
  private onSchemaLoadOrUpdateListeners = new Set<
@@ -189,6 +190,9 @@ export class ApolloGateway implements GatewayInterface {
189
190
  }
190
191
 
191
192
  private initQueryPlanStore(approximateQueryPlanStoreMiB?: number) {
193
+ if(this.config.queryPlannerConfig?.cache){
194
+ return this.config.queryPlannerConfig?.cache
195
+ }
192
196
  // Create ~about~ a 30MiB InMemoryLRUCache (or 50MiB if the full operation ASTs are
193
197
  // enabled in query plans as this requires plans to use more memory). This is
194
198
  // less than precise since the technique to calculate the size of a DocumentNode is
@@ -196,7 +200,7 @@ export class ApolloGateway implements GatewayInterface {
196
200
  // for unicode characters, etc.), but it should do a reasonable job at
197
201
  // providing a caching document store for most operations.
198
202
  const defaultSize = this.config.queryPlannerConfig?.exposeDocumentNodeInFetchNode ? 50 : 30;
199
- return new LRUCache<string, QueryPlan>({
203
+ return new InMemoryLRUCache<QueryPlan>({
200
204
  maxSize: Math.pow(2, 20) * (approximateQueryPlanStoreMiB || defaultSize),
201
205
  sizeCalculation: approximateObjectSize,
202
206
  });
@@ -770,7 +774,7 @@ export class ApolloGateway implements GatewayInterface {
770
774
  span.setStatus({ code: SpanStatusCode.ERROR });
771
775
  return { errors: validationErrors };
772
776
  }
773
- let queryPlan = this.queryPlanStore.get(queryPlanStoreKey);
777
+ let queryPlan = await this.queryPlanStore.get(queryPlanStoreKey);
774
778
 
775
779
  if (!queryPlan) {
776
780
  queryPlan = tracer.startActiveSpan(
@@ -794,7 +798,7 @@ export class ApolloGateway implements GatewayInterface {
794
798
  );
795
799
 
796
800
  try {
797
- this.queryPlanStore.set(queryPlanStoreKey, queryPlan);
801
+ await this.queryPlanStore.set(queryPlanStoreKey, queryPlan);
798
802
  } catch (err) {
799
803
  this.logger.warn(
800
804
  'Could not store queryPlan' + ((err && err.message) || err),
@@ -969,6 +973,7 @@ export class ApolloGateway implements GatewayInterface {
969
973
  state: this.state,
970
974
  compositionId: this.compositionId,
971
975
  supergraphSdl: this.supergraphSdl,
976
+ queryPlanner: this.queryPlanner,
972
977
  };
973
978
  }
974
979
  }