-
Notifications
You must be signed in to change notification settings - Fork 259
Apollo Federation/Gateway doesn't support Cache Control #356
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
Comments
I think a broad statement that could be made of this is that federation doesn't support any custom directives and any origin headers or extensions are dropped in the process of executing queries. |
It does support custom directives, but you need to use
which feels like a bit of a hack/workaround but I'm not sure of another option to include custom directives |
@shaneu To clarify, this issue is about using the Federated Schema tools, not schema stitching. |
@RichiCoder1 understood, I'm saying I've done that workaround above to implement custom directives using federation, I should have included the whole snipped
|
Ah, I see! That's good know and great workaround until this is natively supported. |
@RichiCoder1 @shaneu |
@RichiCoder1 did you get to implement cache on your federated services? |
@donedgardo This issue came out of some exploratory work, so I haven't tackled fixing this personally. |
Also running into this issue. Anyone find a workaround? |
Here is a simple workaround that worked for us. Include the schema for the cacheControl directive when you call
Should work as long as you have |
In reference to @ctpaulson's comment above, we also had to do some additional work in the gateway to ensure that the resulting headers were combined appropriately: First, we create a new datasource that collects the headers:
And we also have a special plugin to calculate the overall cache-control value and set the headers:
And then we wire it all up in the configuration:
|
Any update for when this should get fixed? |
I am very interested in this feature as well. Is this on the roadmap? |
My question is already answered by this document: https://github.com/apollographql/apollo-server/blob/c798068227b446d30b7aa306d2ea8008cd731375/ROADMAP.md#apollo-server-3x
Thanks for writing this up 👍 ❤️ |
It's actually a lot less complicated than this, since the servers behind the gateway actually do respond with the new ApolloGateway({
buildService: ({ url }) =>
new RemoteGraphQLDataSource({
didReceiveResponse({ context: { req, res } = {}, response }) {
const age = response.http?.headers?.get('Age')
if (age) {
res?.append('Age', age)
}
const cacheControl = response.http?.headers?.get('Cache-Control')
if (cacheControl) {
res?.append('Cache-Control', cacheControl)
}
return response
}
})
}) I can't seem to get it to work using Everything works after that except for invalidating the cache for mutations, which ended up killing this for us, but just in case it is helpful for anyone else. |
We're hoping to improve this to work by default. See plan at apollographql/apollo-server#5449 |
It doesn't look like
@apollo/[email protected]
and@apollo/[email protected]
support@cacheControl
directives or cache control hints.Related: apollographql/apollo-server#3181
Expected
Using static or dynamic cacheControl hints will result in cache-control http headers.
Actual
No headers are sent, and the hints are empty when
cacheControl: true
inApolloServer
.Code Example:
Error:
UnhandledPromiseRejectionWarning: GraphQLSchemaValidationError: Unknown directive "cacheControl".
The text was updated successfully, but these errors were encountered: