Skip to content

Commit e28da91

Browse files
committed
Notify users about Apollo In Memory Cache ID
Closes #2379
1 parent ba150c3 commit e28da91

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

docusaurus/docs/cms/plugins/graphql.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,25 @@ To increase GraphQL security even further, 3rd-party tools can be used. See the
10661066

10671067
The GraphQL plugin adds a GraphQL endpoint accessible and provides access to a GraphQL playground, accessing at the `/graphql` route of the Strapi admin panel, to interactively build your queries and mutations and read documentation tailored to your content types. For detailed instructions on how to use the GraphQL Playground, please refer to the official <ExternalLink to="https://www.apollographql.com/docs/apollo-server/v2/testing/graphql-playground" text="Apollo Server documentation"/>.
10681068

1069+
1070+
:::note
1071+
Strapi uses `documentId` as the unique identifier for entities instead of `id`. When using Apollo Client with Strapi's GraphQL API, you need to [configure](https://www.apollographql.com/docs/react/caching/cache-configuration#customizing-identifier-generation-globally) the `InMemoryCache` to use `documentId` for cache normalization:
1072+
1073+
```javascript
1074+
import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client';
1075+
1076+
const client = new ApolloClient({
1077+
link: new HttpLink({ uri: "http://localhost:1337/graphql" }),
1078+
cache: new InMemoryCache({
1079+
dataIdFromObject: (o) => `${o.__typename}:${o["documentId"]}`,
1080+
}),
1081+
});
1082+
```
1083+
1084+
This ensures that Apollo Client correctly caches and updates your GraphQL data based on Strapi's identifier structure.
1085+
:::
1086+
1087+
10691088
### Usage with the Users & Permissions feature {#usage-with-the-users--permissions-plugin}
10701089

10711090
The [Users & Permissions feature](/cms/features/users-permissions) allows protecting the API with a full authentication process.

docusaurus/static/llms-code.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28753,6 +28753,26 @@ export default {
2875328753
```
2875428754

2875528755

28756+
## Usage
28757+
Description: :::note Strapi uses documentId as the unique identifier for entities instead of id.
28758+
(Source: https://docs.strapi.io/cms/plugins/graphql#usage)
28759+
28760+
Language: JavaScript
28761+
File path: N/A
28762+
28763+
```js
28764+
import { ApolloClient, InMemoryCache } from '@apollo/client';
28765+
28766+
const client = new ApolloClient({
28767+
link: new HttpLink({ uri: "http://localhost:1337/graphql" }),
28768+
cache: new InMemoryCache({
28769+
// https://www.apollographql.com/docs/react/caching/cache-configuration#customizing-identifier-generation-globally
28770+
dataIdFromObject: (o) => `${o.__typename}:${o["documentId"]}`,
28771+
}),
28772+
});
28773+
```
28774+
28775+
2875628776
## Registration
2875728777
Description: Code example from "Registration"
2875828778
(Source: https://docs.strapi.io/cms/plugins/graphql#registration)

0 commit comments

Comments
 (0)