-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cache option to config to expose ApolloGateway's queryPlanStore (#…
…2385) Introduce new `queryPlannerConfig.cache` option to gateway constructor to allow query plan cache configuration. Export new `QueryPlanCache` type from `@apollo/query-planner` for implementors.
- Loading branch information
1 parent
6a8dfa3
commit d4426ff
Showing
7 changed files
with
91 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
"@apollo/query-planner": minor | ||
"@apollo/gateway": minor | ||
--- | ||
|
||
This change introduces a configurable query plan cache. This option allows | ||
developers to provide their own query plan cache like so: | ||
|
||
``` | ||
new ApolloGateway({ | ||
queryPlannerConfig: { | ||
cache: new MyCustomQueryPlanCache(), | ||
}, | ||
}); | ||
``` | ||
|
||
The current default implementation is effectively as follows: | ||
``` | ||
import { InMemoryLRUCache } from "@apollo/utils.keyvaluecache"; | ||
const cache = new InMemoryLRUCache<string>({ | ||
maxSize: Math.pow(2, 20) * 30, | ||
sizeCalculation<T>(obj: T): number { | ||
return Buffer.byteLength(JSON.stringify(obj), "utf8"); | ||
}, | ||
}); | ||
``` | ||
|
||
TypeScript users should implement the `QueryPlanCache` type which is now | ||
exported by `@apollo/query-planner`: | ||
``` | ||
import { QueryPlanCache } from '@apollo/query-planner'; | ||
class MyCustomQueryPlanCache implements QueryPlanCache { | ||
// ... | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters