-
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
Gql arguments are required if defined in keyArgs #6973
Comments
Having this exact same issue, let me know if you've come up with a solution! Doesnt seem like |
@zsaraf I believe relayStylePagination and all the other pagination helpers are more guides on how to guide your pagination helper? Either way they should still be usable (and the fact that this affects all keyArgs! not just relayStylePagination). Here is my solution:
Basically you can pass a function into relayStylePagination / keyArgs which will receive the current arguments, then filter out the keyargs which aren't in the arguments. Let me know if you have any trouble with it, it's what i've been using in production for the past couple weeks after removing updateQuery. |
Thank you @tadhglewis! |
The keyArgs:[...] configuration for field policies should be able to include arguments that are optional, while still specifying an ordering of all possible key arguments for serialization purposes. When an optional argument is not provided, it will simply not be included in the serialized storeKeyName suffix, and no exception will be thrown. Should address #6973.
@tadhglewis I think allowing optional arguments in |
As suggested by @tadhglewis in #6973. The [`keyArgs: ["someArg", "anotherArg"]` configuration for field policies](https://www.apollographql.com/docs/react/caching/cache-field-behavior/#specifying-key-arguments) should be able to include arguments that are _optional_, while still specifying an ordering of all possible key arguments for serialization purposes. When an optional argument is not provided, it will simply not be included in the serialized `storeFieldName` suffix, and no exception will be thrown.
It looks like it is currently working. Maybe I did use keyFields instead of
keyArgs ...
Apologies...
Op ma 7 dec. 2020 om 19:15 schreef Ben Newman <[email protected]>:
… @robertsmit <https://github.com/robertsmit> #7109 (comment)
<#7109 (comment)>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6973 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABY2H3667PPBTCZ5GVAILFDSTULSZANCNFSM4QZZCHQQ>
.
|
Can't test whether this is or isn't working as I'm no longer working on the project I was using this on. I'm assuming this is fine to close this issue now. @benjamn ? |
I'm unsure if this is intended behaviour and I can't seem to find much documentation on this feature as the documentation is being worked on (#6711).
I am using relayStylePagination / keyArgs like so
Intended outcome:
keyArgs
should not require the argument to be defined in thegql
query, if a key arg is defined in the InMemoryCache but not the specificgql
, the key arg should be ignoredInMemoryCache
gql
This causes issues if you have a large application with multiple gql files defined for the same field but with different arguments - my current work around is to write a function for the keyArgs and filter them depending on the arguments like so
Actual outcome:
I get the following error (which is worded for key fields) when the
propertyId
key arg is defined in the InMemoryCache but not in thegql
Invariant Violation: Missing field 'propertyId' while computing key fields
keyArgs
without using the pagination helper as well.How to reproduce the issue:
Let me know if you need to create a demo
Versions
The text was updated successfully, but these errors were encountered: