The @apolloapolloapolloapollo/server v5 documentation says to use RESTDataSource@apolloapollofrom @apollo/datasource-rest for interacting with REST APIs to provide caching.
This is not working for me locally and it seems to@apoapollobe because @apo@ap@apollollolo/server v5 has @apollo/utils.keyvaluecache v4@ap@apollolloas a dependency whilst @apollo/da@ap@apollolloasource-rest v6 (latest) has @apollo/utils.keyvaluecache v3 as a dependency.
Has anyone managed to get this to work with @apollo/server v5?
This is my API that extends RESTDataSource:
export class ContextAPI extends RESTDataSource {
override baseURL: string = process.env.CONTEXT_API_URL!;
loggingInfo: Logging;
private static readonly label: string = "context-api";
constructor(loggingInfo: Logging) {
super();
this.loggingInfo = loggingInfo;
}
protected override willSendRequest(
_path: string,
requestOpts: AugmentedRequest<CacheOptions>,
): ValueOrPromise<void> {
requestOpts.headers["tracking-id"] = loggingInfo["tracking-id"];
}
async getContext(context: string) {
return ResultAsync.fromPromise<IContextResponse, GraphQLError>(
this.get("context", {
params: {
context,
},
}),
(e) => {
return new GraphQLError("Failed to get context", {
extensions: {
code: "CONTEXT_ERROR",
},
originalError: toError(e),
});
},
);
}
}
And this is the error I get when I call my Context query in an integration test with executeOperation
"stacktrace": [
"TypeError: Cannot read private member #keyMap from an object whose class did not declare it",
" at LRUCache.get (C:\\Users\\123\\dev\\my-project\\node_modules\\lru-cache\\dist\\commonjs\\index.js:1366:28)",
" at InMemoryLRUCache.get (C:\\Users\\123\\dev\\my-project\\node_modules\\@apollo\\utils.keyvaluecache\\dist\\InMemoryLRUCache.js:29:27)",
" at PrefixingKeyValueCache.get (C:\\Users\\123\\dev\\my-project\\node_modules\\@apollo\\utils.keyvaluecache\\dist\\PrefixingKeyValueCache.js:18:29)",
" at HTTPCache.fetch (C:\\Users\\123\\dev\\my-project\\node_modules\\@apollo\\datasource-rest\\dist\\HTTPCache.js:60:40)",
" at C:\\Users\\123\\dev\\my-project\\node_modules\\@apollo\\datasource-rest\\dist\\RESTDataSource.js:190:101",
" at ContextAPI.trace (C:\\Users\\123\\dev\\my-project\\node_modules\\@apollo\\datasource-rest\\dist\\RESTDataSource.js:274:20)",
" at performRequest (C:\\Users\\123\\dev\\my-project\\node_modules\\@apollo\\datasource-rest\\dist\\RESTDataSource.js:183:25)",
" at ContextAPI.fetch (C:\\Users\\123\\dev\\my-project\\node_modules\\@apollo\\datasource-rest\\dist\\RESTDataSource.js:229:40)",
" at processTicksAndRejections (node:internal/process/task_queues:105:5)",
" at ContextAPI.get (C:\\Users\\123\\dev\\my-project\\node_modules\\@apollo\\datasource-rest\\dist\\RESTDataSource.js:111:17)",
]