You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found the need in my angular app to use the apolloCache.updateQuery function. I wrote a small wrapper to the function so that it can be called and use for any of our queries. However, it's currently not type safe.
My updateQuery wrapper is currently only going to work for one of our graphql queries, such as this one:
My updateQuery wrapper assumes the structure of the OpResult, MyVars and MyQueryDoc. What I'd like to be ale to do is create some typescript type helps that given a specific MyQuery, it can extract or infer MyOpResult, MyVars, and MyQueryDoc, and I can then use those types to provide some type safety to my updateQuery wrapper.
Two questions:
are any utility types available in the apollo library to assist with this? I can't see to find any.
I've tried creating my own utility types, but I'm struggling getting it to work. even trying to get the type of MyOpResult doesn't seem to work.
type OpResult<T> = T extends Apollo.Query<infer R, infer V> ? R : never;
type QueryOpResultType = OpResult<MyQuery>;
// always returns a type of "never"
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I found the need in my angular app to use the apolloCache.updateQuery function. I wrote a small wrapper to the function so that it can be called and use for any of our queries. However, it's currently not type safe.
My updateQuery wrapper is currently only going to work for one of our graphql queries, such as this one:
My updateQuery wrapper assumes the structure of the OpResult, MyVars and MyQueryDoc. What I'd like to be ale to do is create some typescript type helps that given a specific
MyQuery
, it can extract or infer MyOpResult, MyVars, and MyQueryDoc, and I can then use those types to provide some type safety to my updateQuery wrapper.Two questions:
Beta Was this translation helpful? Give feedback.
All reactions