I try to update Apollo cache after running Mutation. For this, i use mutate
method :
client.mutate({
mutation: CREATE_PLAYLIST,
variables: { ...playlistUpdated, users: [1] },
update: cache => {
const { playlists } = cache.readQuery({ query: GET_USER_PLAYIST });
cache.writeQuery({
query: GET_USER_PLAYIST,
data: { playlists: playlists.concat(playlistUpdated) }
});
}
});
But on writeQuery
function, i've this error : TypeError: TypeError: undefined is not an object (evaluating 'data.playlists')
. I'm not really understand why i've this error because data.playlists exist on GET_USER_PLAYIST
query response :/
const GET_USER_PLAYIST = gql`
{
playlists(where: { users: { id: 1 } }) {
name
id
}
}
`;
Anyone can help me ?
Thank you community !
writeQuery
, you're constructing an object with aplaylist
property, but it should beplaylists
based on your query. – Daniel Reardenplaylists
:( – s-leg3ndz