question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apollo cache control - cache hints for code first - default max age

See original GitHub issue

I’m submitting a…


[ ] Regression 
[ ] Bug report
[x] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Is it possible to use the apollo cache control with Nest?
https://www.apollographql.com/docs/apollo-server/features/caching

This is an example code for schema first and the apollo cache control:

type Post @cacheControl(maxAge: 240) {
  id: Int!
  title: String
  author: Author
  votes: Int @cacheControl(maxAge: 30)
  comments: [Comment]
  readByCurrentUser: Boolean! @cacheControl(scope: PRIVATE)
}

Is it possible to use this also with Nest and code first instead of schema first?

I configured my graphql module with this configuration, to use the default max age:

GraphQLModule.forRoot({
  autoSchemaFile: true,
  path: '/api/gql',
  debug: true,
  introspection: true,
  playground: true,
  tracing: true,
  cacheControl: {
    defaultMaxAge: 60,
    stripFormattedExtensions: false,
    calculateHttpHeaders: true
  }
})

This creates the correct response header with cache-control: max-age=60. But it doesn’t work. Every request in the next 60 seconds is not cached. All the time my resolvers will be trigered and generate a new response.

# Response Headers:

HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: application/json
cache-control: max-age=60, public
Content-Length: 873
Date: Wed, 22 May 2019 22:25:41 GMT
Connection: keep-alive
# Request Headers:

POST /api/gql HTTP/1.1
Host: localhost:3000
Connection: keep-alive
Content-Length: 78
accept: */*
Origin: http://localhost:3000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36
DNT: 1
content-type: application/json
Referer: http://localhost:3000/api/gql
Accept-Encoding: gzip, deflate, br
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7

Environment


@nestjs/core: 6.2.4
@nestjs/graphql: 6.2.1

For Tooling issues:
- Node version: 12.2.0
- Platform: Mac, Linux

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
esistgutcommented, Jun 23, 2019

Did you make any progress on this?

0reactions
lock[bot]commented, Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server-side caching - Apollo GraphQL Docs
The setCacheHint method accepts an object with maxAge and scope fields. cacheControl.cacheHint. This object represents the field's current cache hint. Its ...
Read more >
Caching - Apollo GraphQL Docs
@cacheControl can specify maxAge (in seconds, like in an HTTP Cache-Control header) and scope , which can be PUBLIC (the default) or PRIVATE...
Read more >
Stale-while-revalidate Data Fetching with React Hooks: A Guide
When a request is sent for the first time, it's cached by the browser. Then, when the same request is sent a second...
Read more >
Does 'cache-control: public' actually have any effect? [duplicate]
The status code of the response is known by the application caching, and it is considered cacheable. · There are (I assume this...
Read more >
Caching | NestJS - A progressive Node.js framework
The default expiration time of the cache is 5 seconds. You can manually specify a TTL (expiration time in seconds) for this specific...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found