Skip to content

Commit 15ec62e

Browse files
author
Alireza Zamani
committed
Update package name and info
1 parent 01cc2a6 commit 15ec62e

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ This package offers you a simple decorator to set cache control on your resolver
77
On Yarn:
88

99
```shell
10-
yarn add @exonest/graphql-cache-control
10+
yarn add nestjs-gql-cache-control
1111
```
1212

1313
On NPM:
1414

1515
```shell
16-
npm install @exonest/graphql-cache-control
16+
npm install nestjs-gql-cache-control
1717
```
1818

1919
## Usage
@@ -40,12 +40,13 @@ GraphQLModule.forRoot({
4040
],
4141
}),
4242
```
43+
4344
> To add Redis or other caching stores, check [Apollo's docs](https://www.apollographql.com/docs/apollo-server/performance/caching/#in-memory-cache-setup)
4445
4546
Then, you can use the decorator on your queries and field resolvers:
4647

4748
```ts
48-
import { CacheControl } from '@exonest/graphql-cache-control';
49+
import { CacheControl } from 'nestjs-gql-cache-control';
4950

5051
@Resolver((type) => Post)
5152
export class PostResolver {
@@ -55,16 +56,16 @@ export class PostResolver {
5556
// database calls
5657
return posts;
5758
}
58-
59+
5960
@ResolveField(() => User)
6061
@CacheControl({ inheritMaxAge: true })
6162
owner() {
6263
// database calls
6364
return owner;
6465
}
65-
66+
6667
@ResolveField(() => boolean)
67-
@CacheControl({ maxAge: 5, scope: "PRIVATE" })
68+
@CacheControl({ maxAge: 5, scope: 'PRIVATE' })
6869
hasLiked() {
6970
// database calls
7071
return hasLiked;
@@ -75,15 +76,15 @@ export class PostResolver {
7576
## How The Apollo Cache Works
7677

7778
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.
8379

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.
8485
8586
## Connections (Pagination)
8687

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.
8889

8990
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))

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"engines": {
1111
"node": ">=10"
1212
},
13-
"homepage": "https://github.com/exonest",
13+
"homepage": "https://github.com/overnested",
1414
"repository": {
1515
"type": "git",
16-
"url": "https://github.com/exonest/graphql-connections"
16+
"url": "https://github.com/overnested/nestjs-gql-connections"
1717
},
1818
"scripts": {
1919
"start": "tsdx watch",
@@ -36,8 +36,11 @@
3636
"singleQuote": true,
3737
"trailingComma": "es5"
3838
},
39-
"name": "@exonest/graphql-cache-control",
40-
"author": "Alireza Zamani",
39+
"name": "nestjs-gql-cache-control",
40+
"author": {
41+
"email": "alirezazamani2922@gmail.com",
42+
"name": "Alireza Zamani"
43+
},
4144
"module": "dist/graphql-cache-control.esm.js",
4245
"size-limit": [
4346
{

0 commit comments

Comments
 (0)