From 42151ae74cc55306582fefda0d07b77f479e6e5a Mon Sep 17 00:00:00 2001 From: Andrei L <1881266+unrevised6419@users.noreply.github.com> Date: Mon, 1 Dec 2025 14:15:34 +0200 Subject: [PATCH] Notify users about Apollo In Memory Cache ID Closes #2379 --- docusaurus/docs/cms/plugins/graphql.md | 19 +++++++++++++++++++ docusaurus/static/llms-code.txt | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/docusaurus/docs/cms/plugins/graphql.md b/docusaurus/docs/cms/plugins/graphql.md index 4286c933f6..b84363ebaa 100644 --- a/docusaurus/docs/cms/plugins/graphql.md +++ b/docusaurus/docs/cms/plugins/graphql.md @@ -1066,6 +1066,25 @@ To increase GraphQL security even further, 3rd-party tools can be used. See the 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 . + +:::note +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: + +```javascript +import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client'; + +const client = new ApolloClient({ + link: new HttpLink({ uri: "http://localhost:1337/graphql" }), + cache: new InMemoryCache({ + dataIdFromObject: (o) => `${o.__typename}:${o["documentId"]}`, + }), +}); +``` + +This ensures that Apollo Client correctly caches and updates your GraphQL data based on Strapi's identifier structure. +::: + + ### Usage with the Users & Permissions feature {#usage-with-the-users--permissions-plugin} The [Users & Permissions feature](/cms/features/users-permissions) allows protecting the API with a full authentication process. diff --git a/docusaurus/static/llms-code.txt b/docusaurus/static/llms-code.txt index cca1062ebe..036bb4e480 100644 --- a/docusaurus/static/llms-code.txt +++ b/docusaurus/static/llms-code.txt @@ -28753,6 +28753,25 @@ export default { ``` +## Usage +Description: :::note Strapi uses documentId as the unique identifier for entities instead of id. +(Source: https://docs.strapi.io/cms/plugins/graphql#usage) + +Language: JavaScript +File path: N/A + +```js +import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client'; + +const client = new ApolloClient({ + link: new HttpLink({ uri: "http://localhost:1337/graphql" }), + cache: new InMemoryCache({ + dataIdFromObject: (o) => `${o.__typename}:${o["documentId"]}`, + }), +}); +``` + + ## Registration Description: Code example from "Registration" (Source: https://docs.strapi.io/cms/plugins/graphql#registration)