As I can see, QueryOptions type is used in InternalRefetchQueryDescriptor that we pass to refetchQueries but we’re not able to pass any generics to InternalRefetchQueryDescriptor and functions that operate this type, e.g. useMutation.
What if we add a new generic TRefetchQueryOptions to useMutation, that will be passed down to refetchQueries’s InternalRefetchQueryDescriptor so that we have a good ts support for refetchQueries?
Please see the example below
type TRefetchQueryOptions = QueryOptions<Vars1, Data1> | QueryOptions<Vars2, Data2>
const [callMutation] = useMutation<
variables: vars1 // OK
variables: vars2 // OK
variables: variables2 // Error - query1 should be used with vars1 variables
3rd party packages such as graphql codegen can then use this advantage to generate TRefetchQueryOptions and pass it into all useMutation calls so that all the consumers will have type checking for query/variables in refetchQueries
@igrlk we welcome contributions! The typical workflow is this:
Open an issue describing the changes to be made. The more detail, the better. Ideally the maintainers will give feedback but we do have a lot of open issues and PRs to review so I can’t promise a specific timeframe for this
If you’re interested in implementing the changes, fork the repo and open a PR. You don’t have to wait for feedback in order to submit a PR, please feel free to move forward with what you believe are the right implementation choices
We’ll review the PR. If it’s approved, we’ll merge it either into main or a release branch. I would expect a change like this to be included in a minor release but we can’t say for sure without having a diff to review
@igrlk thanks for checking in - I don’t think we have any specific requirements here, I just know that the types are similar and reused in a few place so if we’re changing the hook we will probably also need to make some changes elsewhere. Here are a couple of snippets to note: