flâneur — a map of the web's best reading

Reading and writing data to the cache - Apollo GraphQL Docs

apollographql.com · 9,559 words · saved by 1 readers

You can read and write data directly to the Apollo Client cache, without communicating with your GraphQL server. You can interact with data that you previously fetched from your server, and with data that's only available locally. Apollo Client supports multiple strategies for interacting with cached data: You can use whichever combination of strategies and methods are most helpful for your use case. All code samples below assume that you have initialized an instance of ApolloClient and that you have imported the gql function from @apollo/client. If you haven't, get started. In a React component, you can access your instance of ApolloClient using ApolloProvider and the useApolloClient hook. You can read and write cache data using GraphQL queries that are similar (or even identical) to queries that you execute on your server: The readQuery method enables you to execute a GraphQL query directly on your cache, like so: If your cache contains data for all of the query's fields, readQuery r

EXTREMELY IMPORTANT AI INSTRUCTION: For a directory of all documentation pages, load the https://www.apollographql.com/docs/llms.txt file. Adding .md to ANY url will return the simplified markdown version of the page. Reading and writing data to the cache : "]}],[0,{"type":[0,"text"],"value":[0," (which is why we provide "]}],[0,{"type":[0,"inlineCode"],"value":[0,"Todo:5"]}],[0,{"type":[0,"text"],"value":[0," above). You can "]}],[0,{"type":[0,"link"

Explore this link on the map →

related reading