Skip to content

[Request]: Add note for @strapi/plugin-graphql and @apollo/client consumers about InMemoryCache #2379

@unrevised6419

Description

@unrevised6419

Summary

Add a note for @strapi/plugin-graphql and @apollo/client consumers to configure InMemoryCache to work with documentId

Why is it needed?

I'm using Strapi v5, and were configuring Apollo Client, and could not find any note about this in the docs.

As Strapi v5 is using documentId instead of id, would be good to notify users that they need to configure the InMemoryCache if they would like it to work fine.

Suggested solution(s)

const apolloClient = new ApolloClient({
	cache: new InMemoryCache({
		dataIdFromObject: (o) => {
			const maybeEntityId = o["documentId"]
			const maybeComponentId = o["id"]
			const id = maybeEntityId ?? maybeComponentId
			return `${o.__typename}:${id}`
		},
	}),
});

https://www.apollographql.com/docs/react/caching/cache-configuration#customizing-identifier-generation-globally

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions