-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add generic types to apollo client for Query and Mutation #914
add generic types to apollo client for Query and Mutation #914
Conversation
@kamilkisiela do you have a moment to review this PR? I'm asking since you initially had the idea for #777 |
@helfer I don't get the idea. Why we specify those types while creating an instance of ApolloClient<QueryType, MutationType> and public watchQuery(...): ObservableQuery<QueryType, MutationType> With this approach, every My idea was to specify generic type for each individual For example: apollo.watchQuery<Entry[]>({query: feedQuery});
// returns { data: Entry[], loading: boolean, ... }
apollo.watchQuery<Entry>({query: entryQuery, variables: { id: 2 }});
// returns { data: Entry, loading: boolean, ... } |
@kamilkisiela is this more what you're looking for? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is be a breaking change if it comes to TypeScript based projects.
Right now we use it like this:
apollo.watchQuery({ query });
It will cause a warning about a missing generic type, so it's up to you guys if you want to release it in v0.5.X
.
unfortunately, generics cannot be made optional (there's an issue here: microsoft/TypeScript#2175), so yes, it will be a breaking change, but quite an easy one to fix (just add |
@brettjurgens Yes yes, it's not that I see it as a big problem, it's just a breaking change that will screw up few projects if we will push it as |
agreed, should not be released in a patch version. |
This update sure would go well with working TypeScript code gen: apollographql/apollo-tooling#5 |
@stubailo FWIW there's also https://github.com/avantcredit/gql2ts |
@brettjurgens Sorry I did't get around to doing anything with this PR until now! Do you think you could you change the base of this PR to zero-decimal-six and resolve all the conflicts in the next few days? If so, then we can merge it and release it with version 0.6. Otherwise I think we should probably close the PR and open a new one down the road, because it will only get harder to merge the PR as it gets more out of date with the rest of the code. |
@brettjurgens yes, it would be super cool. I could make changes also in |
cool, will rebase on 0.6 right now |
This reverts commit 0c2aa46.
…ns/apollo-client into add_generics_to_apollo_client
@helfer just rebased it and the diff between this branch and the |
@helfer tests are passing now, seems i missed a conflict or two when the base changed. should be all good now |
@brettjurgens wonderful, thanks for your efforts! It always feels great to merge the oldest PR 😌 |
Fixes #777
TODO: