score:4
every object should return id, _id or alternatively a custom id field (https://www.apollographql.com/docs/react/caching/cache-configuration) for automatic merges to function.
const cache = new inmemorycache({
typepolicies: {
product: {
keyfields: ["custom-id-field"],
},
},
});
(!)people often forget that cache operations require the same variables used for the initial query (!)
mutation sample (adding a purchase):
update(cache, { data: newpurchase } }) => {
let productcache = cache.readquery({
query: productquery,
variables: {
id: productid
}
})
cache.writequery({
query: productquery,
variables: { id: productid },
data: {
product: {
...productcache.product,
purchases: productcache.product.purchases.concat(newpurchase)
}
}
});
};
}
(important: each purchase also requires it's own individual id that needs to be returned)
score:10
you may need to return an id for apollo to uniquely identify that object in the cache. i think this issue is similar to yours: link
const confirmation_code = gql`
query {
my {
id
sendnewtokenforconfirmation
}
}
`;
Source: stackoverflow.com
Related Query
- Cache data may be lost when replacing the my field of a Query object
- Cache data may be lost when replacing the getPosts field of a Query object. Apollo
- Apollo client v3 "Cache data may be lost when replacing the field X of a Y object"
- React redux First object missing on rendering when data is entered in the text field
- Is there a way to detect when data used by a query is evicted from the Apollo Client cache?
- Apollo Client client.readQuery returning null when data is in the cache
- Apollo query has the wrong data from cache
- How to make the Service Worker cache data from API and update the cache when needed
- Apollo Cache - Missing selection set for object of type undefined returned for query field names
- Data from the object doesn't convert when using JSON.stringify
- Input field (using downshift) is clearing the entered data when click on div other than submit and input field
- I get data from Api but when I try to set the value with useState it give me an empty object
- RTK Query in Redux-Toolkit is returning data of undefined, when I console.log the data it appears in console
- Redux reducer: Add object to array when the array doesn't have the object data
- Data from the backend is not appearing when you assign it into new object on the front end
- One of attribute lost data when assign javascript object
- It takes ages to type into the styled M-UI TextFields when I call onChange collecting input field data in react
- react-router v3: How to load data for the component when the same route with different query params is loaded
- SQL promise in NodeJS returning empty brackets, but when same query is executed in SQL workbench, it returns the correct data
- How to trigger a graphql query (via useQuery or useLazyQuery ) when the user types text into a input text field
- Intial Output disappears when I change the enter some data in another field
- how to order firebase firestore data by the field's value i.e. "reason" field name and its values may be "spam", "nudity" etc
- when I try to destructing the data from react query I am getting Property 'data' does not exist on type 'void'
- Data pushed in a json object erases when the page is refreshed
- when i write the data in the input field and click submit button , it's told me that the data is undefined
- when map function is in the code it returns undefined and when console.log it returns the an empty object and an the data. i just want the data
- When toggling some data in state, the update to the store is causing some other data to be lost
- Error when creating new object from existing one using `...`: In this environment the sources for assign MUST be an object
- Error: useHref() may be used only in the context of a <Router> component. It works when I directly put the url as localhost:3000/experiences
- How do I see state when logging to the console instead of Proxy object inside reducer action?
More Query from same tag
- React-Redux: visualize elements array
- No 'Access-Control-Allow-Origin' header is present on the requested resource Django and ReactJS
- posts are not in order. want to show latest post at top first
- ant design v4 breaks react testing library tests for Select and Autocomplete
- Declaring routes using an array
- use axios.patch with a nested JSON
- Syntax React single-quote/double-quote <Link to=></Link>
- Using craco in new react project - what would cause this error ? (UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_VALUE]: ...)
- return array of objects from props React JS
- In Redux Form, how can I set the initial value of the checked property of a checkbox?
- Programatically changing a FieldArray value in Redux-Form
- How to move data based on index to different tables
- Put Border Color React Material Theme
- How do I read a \n in a string variable typescript
- Background-color in ReactJS
- Materials UI: Can't get useStyles to work in Class Component
- How to filter json api data with condition using react
- Correct way to cleanup useEffect with Promise
- Why ReactDOMServer.renderToString not returning raw HTML
- don't know where to use .map() so I can see all my json results
- Formik pass customized Props to custom Field Component
- Export .scss to build folder?
- React component props don't get updated with redux store
- Unexpected behavior with useState hook React
- How to monitor user clicks with APM React
- What do you lose by ejecting a React app that was created using create-react-app?
- how to use generics in react function components with RefForwardingComponent?
- Passing variables into arrow function
- Higher-Order Components and APi of React
- react-virtuoso: overscan props does not work