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
Copy file name to clipboardExpand all lines: README.md
+13-12Lines changed: 13 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,13 +7,13 @@ This package offers you a simple decorator to set cache control on your resolver
7
7
On Yarn:
8
8
9
9
```shell
10
-
yarn add @exonest/graphql-cache-control
10
+
yarn add nestjs-gql-cache-control
11
11
```
12
12
13
13
On NPM:
14
14
15
15
```shell
16
-
npm install @exonest/graphql-cache-control
16
+
npm install nestjs-gql-cache-control
17
17
```
18
18
19
19
## Usage
@@ -40,12 +40,13 @@ GraphQLModule.forRoot({
40
40
],
41
41
}),
42
42
```
43
+
43
44
> To add Redis or other caching stores, check [Apollo's docs](https://www.apollographql.com/docs/apollo-server/performance/caching/#in-memory-cache-setup)
44
45
45
46
Then, you can use the decorator on your queries and field resolvers:
Please carefully read [Apollo's docs about caching](https://www.apollographql.com/docs/apollo-server/performance/caching/) to understand how caching works, since it has a set of rules for cache calculation. In a brief:
78
-
>a response should only be considered cacheable if every part of that response opts in to being cacheable. At the same time, we don't think developers should have to specify cache hints for every single field in their schema.
79
-
So, we follow these heuristics:
80
-
Root field resolvers are extremely likely to fetch data (because these fields have no parent), so we set their default maxAge to 0 to avoid automatically caching data that shouldn't be cached.
81
-
Resolvers for other non-scalar fields (objects, interfaces, and unions) also commonly fetch data because they contain arbitrarily many fields. Consequently, we also set their default maxAge to 0.
82
-
Resolvers for scalar, non-root fields rarely fetch data and instead usually populate data via the parent argument. Consequently, these fields inherit their default maxAge from their parent to reduce schema clutter.
83
79
80
+
> a response should only be considered cacheable if every part of that response opts in to being cacheable. At the same time, we don't think developers should have to specify cache hints for every single field in their schema.
81
+
> So, we follow these heuristics:
82
+
> Root field resolvers are extremely likely to fetch data (because these fields have no parent), so we set their default maxAge to 0 to avoid automatically caching data that shouldn't be cached.
83
+
> Resolvers for other non-scalar fields (objects, interfaces, and unions) also commonly fetch data because they contain arbitrarily many fields. Consequently, we also set their default maxAge to 0.
84
+
> Resolvers for scalar, non-root fields rarely fetch data and instead usually populate data via the parent argument. Consequently, these fields inherit their default maxAge from their parent to reduce schema clutter.
84
85
85
86
## Connections (Pagination)
86
87
87
-
If you happen to use [@exonest/graphql-connections](https://github.com/exonest/graphql-connections), `edges` and `node` will automatically inherit cache control from their parents. but otherwise you should set `inheritMaxAge` on your connection fields to prevent connections from cancelling your cache.
88
+
If you happen to use [nestjs-gql-connections](https://github.com/overnested/nestjs-gql-connections), `edges` and `node` will automatically inherit cache control from their parents. but otherwise you should set `inheritMaxAge` on your connection fields to prevent connections from cancelling your cache.
88
89
89
90
Why you should do that? because you probably don't want your connections to cancel your cache control. ([learn more](https://www.apollographql.com/docs/apollo-server/performance/caching/#default-maxage))
0 commit comments