Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Type Helpers#2193

Unanswered
BoilerTom90 asked this question inQ&A
Mar 2, 2024· 0 comments
Discussion options

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:

@Injectable({providedIn: 'root'})export class MyQuery extends Apollo.Query<MyOpResult,MyVars> {override document = MyQueryDoc;override client = 'myApi';constructor(apollo: Apollo.Apollo) {super(apollo);}}

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 specificMyQuery, 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:

  1. are any utility types available in the apollo library to assist with this? I can't see to find any.
  2. 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"
You must be logged in to vote

Replies: 0 comments

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@BoilerTom90

[8]ページ先頭

©2009-2025 Movatter.jp