-
-
Notifications
You must be signed in to change notification settings - Fork 460
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
(vue) useQuery loses typing of variables #3733
Comments
It seems to me that there are multiple issues with the typing (apologies if I'm misunderstanding). Notably, Before fixing this issue, it should be made clear exactly what kind of reactive variable we can pass to useQuery et al. What is implemented now is the following:
(As a side note, the first two should be called respectively The current implementation of
For example, unwrapDeeply({
foo: ref('toto'),
bar: [0, () => 'a', ref(true)],
baz: () => ({
a: ref(1),
b: null,
}),
}); returns {
foo: 'toto',
bar: [0, 'a', true],
baz: {
a: 1,
b: null,
},
} Is this really what we need? I'm not sure about unwrapping arrays for example ( Also, is there a use case for having a reactive & GraphQLRequestParams<Data, MaybeRefObj<Variables>> is enough, but again I am probably missing some use cases. Anyway, there seems to be something to discuss here. |
A side question about this type (in vue/core): type GraphQLRequestParams<
Data = any,
Variables extends AnyVariables = AnyVariables,
> =
| ({
query: string | Data;
} & (Variables extends void
? {
variables?: Variables;
}
: Variables extends {
[P in keyof Variables]: Exclude<Variables[P], null | void>;
}
? Variables extends {
[P in keyof Variables]: never;
}
? {
variables?: Variables;
}
: {
variables: Variables;
}
: {
variables?: Variables;
}))
| {
query: string | Data;
variables: Variables;
}; As I understand it (and after some tests), it makes the |
Bump in to the same problem.😵 |
Describe the bug
I'm using GraphQL codegen for typing. Here is an MWE (I also made a repo to show the issue -- see the reproduction link):
The problem comes from this commit. If you revert
to
then the type of the variables is correctly inferred, and the above examples produce a type error.
Not sure if one can revert the aforementioned commit without breaking something else... (I can investigate if need be.)
Reproduction
https://github.com/arkandias/urql-vue-variables-typing-issue
Urql version
"dependencies": {
"@urql/vue": "^1.4.2",
"graphql": "^16.10.0",
"vue": "^3.5.13"
},
"devDependencies": {
"@graphql-codegen/cli": "^5.0.3",
"@graphql-codegen/client-preset": "^4.5.1",
"@graphql-typed-document-node/core": "^3.2.0",
"@vitejs/plugin-vue": "^5.2.1",
"@vue/tsconfig": "^0.7.0",
"typescript": "~5.6.3",
"vite": "^6.0.5",
"vue-tsc": "^2.2.0"
}
Validations
The text was updated successfully, but these errors were encountered: