You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 26, 2023. It is now read-only.
When calculateHttpHeaders is set to true for each request the lowest max age should be caculated for the Cache-Control header. However this is not the case if the @cacheControl directive is set to 0 in the schema.
For example, if the defaultMaxAge is set to 100 and in the schema there is a @cacheControl(maxAge: 0) directive, the Cache-Control header should not be set. However with the current implementation it will be set to max-age=100, public.
The same is the case if defaultMaxAge is set to 0 and the @cacheControl directive of a field should override the one on type level. Here is an example implementation for this:
const{ ApolloServer, gql }=require('apollo-server');constbooks=[{title: 'Harry Potter and the Chamber of Secrets',author: 'J.K. Rowling',}];consttypeDefs=gql` type Book @cacheControl(maxAge: 120) { title: String @cacheControl(maxAge: 0) author: String } type Query { books: [Book] }`;constresolvers={Query: {books: ()=>books,},};constserver=newApolloServer({
typeDefs,
resolvers,cacheControl: {calculateHttpHeaders: true,defaultMaxAge: 0,stripFormattedExtensions: false}});server.listen().then(({ url })=>console.log(`🚀 Server ready at ${url}`));
Query with: curl -sv 'http://localhost:4000/?query=%7Bbooks%7Btitle%7D%7D'
Expected: no cache-control header
Actual: cache-control: max-age=120, public
The bug seems to be caused by this conditional, which evaluates to false if the checked variable is 0:
When
calculateHttpHeaders
is set totrue
for each request the lowest max age should be caculated for theCache-Control
header. However this is not the case if the@cacheControl
directive is set to0
in the schema.For example, if the
defaultMaxAge
is set to100
and in the schema there is a@cacheControl(maxAge: 0)
directive, theCache-Control
header should not be set. However with the current implementation it will be set tomax-age=100, public
.The same is the case if
defaultMaxAge
is set to0
and the@cacheControl
directive of a field should override the one on type level. Here is an example implementation for this:Query with:
curl -sv 'http://localhost:4000/?query=%7Bbooks%7Btitle%7D%7D'
Expected: no
cache-control
headerActual:
cache-control: max-age=120, public
The bug seems to be caused by this conditional, which evaluates to
false
if the checked variable is0
:The text was updated successfully, but these errors were encountered: