Using cache.invalidate TS is complaining about SystemFields.id?: string | number #1462
Answered
by
kitten
frederikhors
asked this question in
Q&A
-
I have this code: type Updates = {
Mutation: {
playerCreate: UpdateResolver;
playerDelete: UpdateResolver;
};
};
const updates: Updates = {
Mutation: {
playerCreate: (result, args, cache): UpdateResolver => {
// ...
},
playerDelete: (result, args, cache, info): UpdateResolver => {
if (result.playerDelete) {
cache.invalidate({ __typename: "Player", id: info.variables.id }); // here the problem!
}
},
},
}; Typescript is complaining about:
Why? |
Beta Was this translation helpful? Give feedback.
Answered by
kitten
Mar 18, 2021
Replies: 1 comment
-
It's because the type is extremely generic with every possible GraphQL scalar value (or sometimes even objects, depending on the method call), so you'll need to cast Also on a side note, you likely don't want to use |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
frederikhors
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's because the type is extremely generic with every possible GraphQL scalar value (or sometimes even objects, depending on the method call), so you'll need to cast
id
, e.g.id as string
. That's until we add type generation for Graphcache.Also on a side note, you likely don't want to use
info.variables
and only use it if there's no alternative. Instead it looks likeargs.id
or sth may be available forplayerDelete
depending on your schema.