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
Unable to use contextQueries when key contains 2 variables #39
Comments
Here is the codesandbox link https://codesandbox.io/s/bold-http-w1wpbp?file=/pages/index.tsx |
Hi @Kamahl19, as you can see in the release notes for v1.0, the So for you case you'd need for it to be: export const keys = createQueryKeys('user', {
byId: (accountId: string, userId: string) => ({
queryKey: [{ accountId, userId }],
contextQueries: {
likes: null,
},
}),
}); |
@lukemorales Hey, thanks for the response. What is the reason of this constrain? Also why is an array allowed here
but not here
It should return the same output, no? |
You're correct @Kamahl19,
To be honest, that seems like a left over from the past implementation that shouldn't be there 😅. The javascript output should indeed be the same, however the inferred types are not, and like I mentioned earlier, it was a tradeoff in order to introduce the nested queries and query options feature while not making the type system more complex than it need to be |
@lukemorales Are you saying all the keys should be 1 item tuples |
@Kamahl19 yes, the tuple can contain a primitive or an object: [string]
[number]
[boolean]
[{ keys }] |
@lukemorales Understood, thanks. I was confused by probably outdated examples such as https://github.com/lukemorales/query-key-factory/blob/main/README.md?plain=1#L56 and |
@Kamahl19 oh yeah, definitely outdated examples, thanks for bringing me attention to them. I'll make sure to update the readme and prevent this confusion again. |
@lukemorales Sorry for my naive question but... why not a simple API supporting all valid keys such as:
There is no magic (prepending strings based on obj keys), no null keys, it allows all valid query keys and no _ctx and _def fields. The output would be:
|
Maybe I dont get something but this code produces this error:
Type '[string, string]' is not assignable to type 'readonly [ValidValue]'. Source has 2 element(s) but target allows only 1.
The text was updated successfully, but these errors were encountered: