-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apollo Server 2.0 - Caching #1163
Changes from 1 commit
8f74518
1c23535
f8658b9
4f25000
395da0f
dbd8288
eda8ce9
80d074f
e6aae1d
29d5998
7b2d694
b39db20
93d21f8
6548196
1703e27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,15 @@ export abstract class RESTDataSource<TContext = any> { | |
httpCache!: HTTPCache; | ||
context!: TContext; | ||
|
||
willSendRequest?(request: Request): void; | ||
public willSendRequest?(request: Request): void; | ||
|
||
public willReceiveCache(httpCache: HTTPCache) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, not sure I understand the benefits of this. It will actually open up users to mistakes when they override these methods and forget to call super (or set the properties themselves). If the idea is that we'd like to have a lifecycle method that's called when the datasource is fully initialized, we should probably define it separately and call it when both cache and context have been set. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense! We don't want users to mess with those "lifecycles", then we should probably have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @glasser pointed out that these names aren't the best, since the data source is really just receiving the cache, so something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not convinced we need these at all, but if we do I like the consistency with React's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. want to make sure #1163 (comment) doesn't get buried |
||
this.httpCache = httpCache; | ||
} | ||
|
||
public willReceiveContext(context: TContext) { | ||
this.context = context; | ||
} | ||
|
||
protected async get( | ||
path: string, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import { | |
} from 'graphql'; | ||
import { GraphQLExtension } from 'graphql-extensions'; | ||
import { EngineReportingAgent } from 'apollo-engine-reporting'; | ||
import { InMemoryKeyValueCache } from 'apollo-datasource-rest'; | ||
|
||
import { | ||
SubscriptionServer, | ||
|
@@ -121,6 +122,10 @@ export class ApolloServerBase { | |
delete requestOptions.persistedQueries; | ||
} | ||
|
||
if (!requestOptions.cache) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should stick to the philosophy that all extra features can be turned off with |
||
requestOptions.cache = new InMemoryKeyValueCache(); | ||
} | ||
|
||
this.requestOptions = requestOptions as GraphQLOptions; | ||
this.context = context; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally like variable scopes explicit,
public
in this case.