mirror of
https://github.com/vale981/apollo-server
synced 2025-03-04 17:21:42 -05:00
checkpoint for full query cache
This commit is contained in:
parent
18e47ea7f3
commit
b7e046004c
5 changed files with 71 additions and 3 deletions
7
package-lock.json
generated
7
package-lock.json
generated
|
@ -2296,6 +2296,13 @@
|
|||
"apollo-server-plugin-base": {
|
||||
"version": "file:packages/apollo-server-plugin-base"
|
||||
},
|
||||
"apollo-server-plugin-full-query-cache": {
|
||||
"version": "file:packages/apollo-server-plugin-full-query-cache",
|
||||
"requires": {
|
||||
"apollo-server-caching": "file:packages/apollo-server-caching",
|
||||
"apollo-server-plugin-base": "file:packages/apollo-server-plugin-base"
|
||||
}
|
||||
},
|
||||
"apollo-server-testing": {
|
||||
"version": "file:packages/apollo-server-testing",
|
||||
"requires": {
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
"apollo-server-lambda": "file:packages/apollo-server-lambda",
|
||||
"apollo-server-micro": "file:packages/apollo-server-micro",
|
||||
"apollo-server-plugin-base": "file:packages/apollo-server-plugin-base",
|
||||
"apollo-server-plugin-full-query-cache": "file:packages/apollo-server-plugin-full-query-cache",
|
||||
"apollo-server-testing": "file:packages/apollo-server-testing",
|
||||
"apollo-tracing": "file:packages/apollo-tracing",
|
||||
"graphql-extensions": "file:packages/graphql-extensions"
|
||||
|
|
|
@ -2,19 +2,77 @@
|
|||
import {
|
||||
ApolloServerPlugin,
|
||||
GraphQLRequestListener,
|
||||
GraphQLRequestContext,
|
||||
} from 'apollo-server-plugin-base';
|
||||
// import { ApolloError } from 'apollo-server-errors';
|
||||
import { KeyValueCache } from 'apollo-server-caching';
|
||||
|
||||
interface Options {}
|
||||
// XXX Duplicates non-exported type from apollo-server-plugin-base.
|
||||
type ValueOrPromise<T> = T | Promise<T>;
|
||||
|
||||
interface Options<TContext = Record<string, any>> {
|
||||
// Underlying cache used to save results. All writes will be under keys that
|
||||
// start with 'fqc:' and are followed by a fixed-size cryptographic hash of a
|
||||
// JSON object with keys representing the query document, operation name,
|
||||
// variables, and other keys derived from the sessionId and extraCacheKeyData
|
||||
// hooks. If not provided, use the cache in the GraphQLRequestContext instead
|
||||
// (ie, the cache passed to the ApolloServer constructor).
|
||||
cache?: KeyValueCache;
|
||||
|
||||
// Define this hook if you're setting any cache hints with scope PRIVATE.
|
||||
// This should return a session ID if the user is "logged in", or null if
|
||||
// there is no "logged in" user.
|
||||
//
|
||||
// If a cachable response has any PRIVATE nodes, then:
|
||||
// - If this hook is not defined, a warning will be logged.
|
||||
// - Else if this hook returns null, it will not be cached.
|
||||
// - Else it will be cached under a cache key tagged with the session ID and
|
||||
// mode "private".
|
||||
//
|
||||
// If a cachable response has no PRIVATE nodes, then:
|
||||
// - If this hook is not defined or returns null, it will be cached under a cache
|
||||
// key tagged with the mode "no session".
|
||||
// - Else it will be cached under a cache key tagged with the mode
|
||||
// "authenticated public".
|
||||
//
|
||||
// When reading from the cache:
|
||||
// - If this hook is not defined or returns null, look in the cache under a cache
|
||||
// key tagged with the mode "no session".
|
||||
// - Else look in the cache under a cache key tagged with the session ID and the
|
||||
// mode "private". If no response is found in the cache, then look under a cache
|
||||
// key tagged with the mode "authenticated public".
|
||||
//
|
||||
// This allows the cache to provide different "public" results to anonymous
|
||||
// users and logged in users ("no session" vs "authenticated public").
|
||||
//
|
||||
// A common implementation of this hook would be to look in
|
||||
// requestContext.request.http.headers for a specific authentication header or
|
||||
// cookie.
|
||||
//
|
||||
// This hook may return a promise because, for example, you might need to
|
||||
// validate a cookie against an external service.
|
||||
sessionId?(
|
||||
requestContext: GraphQLRequestContext<TContext>,
|
||||
): ValueOrPromise<string | null>;
|
||||
|
||||
// Define this hook if you want the cache key to vary based on some aspect of
|
||||
// the request other than the query document, operation name, variables, and
|
||||
// session ID. For example, responses that include translatable text may want
|
||||
// to return a string derived from
|
||||
// requestContext.request.http.headers.get('Accept-Language').
|
||||
extraCacheKeyData?(
|
||||
requestContext: GraphQLRequestContext<TContext>,
|
||||
): ValueOrPromise<string | null>;
|
||||
}
|
||||
|
||||
export default function plugin(options: Options = Object.create(null)) {
|
||||
let cache: KeyValueCache;
|
||||
// let cache: KeyValueCache;
|
||||
console.log(options);
|
||||
|
||||
return (): ApolloServerPlugin => ({
|
||||
requestDidStart(): GraphQLRequestListener<any> {
|
||||
return {
|
||||
async didResolveOperation({ request: { query }, queryHash }) {},
|
||||
async didResolveOperation({}) {},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
{ "path": "./packages/apollo-server-lambda" },
|
||||
{ "path": "./packages/apollo-server-micro" },
|
||||
{ "path": "./packages/apollo-server-plugin-base" },
|
||||
{ "path": "./packages/apollo-server-plugin-full-query-cache" },
|
||||
{ "path": "./packages/apollo-server-testing" },
|
||||
{ "path": "./packages/apollo-tracing" },
|
||||
{ "path": "./packages/graphql-extensions" },
|
||||
|
|
|
@ -20,5 +20,6 @@
|
|||
{ "path": "./packages/apollo-server-koa/src/__tests__/" },
|
||||
{ "path": "./packages/apollo-server-lambda/src/__tests__/" },
|
||||
{ "path": "./packages/apollo-server-micro/src/__tests__/" },
|
||||
{ "path": "./packages/apollo-server-plugin-full-query-cache/src/__tests__/" },
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue