In a react native project I am creating an object and then redirecting the screen to the newly created object's details page and I'm getting this error:
Possible Unhandled Promise Rejection (id: 0): Network error: Store error: the application attempted to write an object with no provided id but the store already contains an id of XYZ for this object.
Looking in the database I see that the item is properly created in the previous step. Navigating to the same screen and item through a list (not after a create and redirect) seems to work fine. Do I have to wait or somehow set some sort of timing for the apollo store to stay correct?
I'm using the standard apollo client @graphql binding/wrapping
gql:
query getEvent($eventId: ID!) {
Event(id:$eventId) {
id
headline
photo
location
startTime
creator {
username
photo
}
}
}
`;
And here's a code snippet
@graphql(getEventGql,{
options: ({route}) => {
console.log('route params', route.params);
return {
variables: {
eventId: route.params.eventId,
}
}
},
})
@connect((state) => ({ user: state.user }))
export default class EventDetailScreen extends Component {
...
Throwing errorsApollo Server throws errors of most built-in types automatically when applicable. For example, it throws a ValidationError whenever an incoming operation isn't valid against the server's schema. Your resolvers can also throw errors in situations where Apollo Server doesn't do so automatically.
By default, Apollo Client throws away partial data and populates the error. graphQLErrors array of your useQuery call (or whichever hook you're using). You can instead use these partial results by defining an error policy for your operation. If the response includes GraphQL errors, they are returned on error.
Resetting the cache This method is asynchronous, because it also refetches any of your active queries. To reset the cache without refetching active queries, use client. clearStore() instead of client. resetStore() .
Overview. Apollo Client stores the results of your GraphQL queries in a local, normalized, in-memory cache. This enables Apollo Client to respond almost immediately to queries for already-cached data, without even sending a network request.
You have to add id
also to the creator
field:
query getEvent($eventId: ID!) {
Event(id:$eventId) {
id
headline
photo
location
startTime
creator {
id
username
photo
}
}
}
In general, make sure to add id
to all subselections of your queries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With