-
Notifications
You must be signed in to change notification settings - Fork 7
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
addTypePolicies does not work as expected for local fields #378
Comments
Wow now that I spent all that effort I think the issue is that we were not waiting to call useTypePolicies(DEFAULT_TYPES);
const [runQuery, { data, loading, error }] = useLazyQuery(GET_TEXT);
useEffect(() => {
runQuery();
}, [runQuery]); |
So if you want to load type policies via |
Yes, I believe so, as
I think resolvers/ |
Thanks @sirugh I just found this PR that adds docs, but it is out of date. apollographql/apollo-client#6766 |
Please note that it's not possible to go back in time whenever In my mind, this reality implies you should either add all your type policies at application initialization time (probably just using the In other words, I want to underscore @sirugh's finding that the order of |
Thanks for the quick response @benjamn. I'll relay this to our team. Could you clarify what you mean by this:
What do you mean by "used"? Our use case is the ability for folks to arbitrarily inject, at runtime, custom types. Like a plugin or extension point. Lastly, do you have any advice for how one might be alerted to the successful addition of a policy via addTypePolicies? |
Implementation-wise, there's a private Although you could maybe get away with adding a few more fields to a type policy after @sirugh Would that be a useful rule to enforce, in your case? |
Is it guaranteed to fail if you call |
It's not currently guaranteed to fail, but I'm in favor of making |
Sounds like a breaking change - which would be fine so long as you let me know about it via a major bump or just...tell me :) |
Intended outcome:
Type Policies for local state fields added through
addTypePolicies
at render/mount of component should allow for querying of those fields from that point on.Actual outcome:
Type Policies for local state fields added through
addTypePolicies
at render/mount of component return undefineddata
and no errors.loading
state indicates that the query executed.Note: I dug into the
addTypePolicies
call and for both scenarios it seems like the type is added. The image shows the same resulting state for adding policy via initialization or adding policy via component callingaddTypePolicies
.How to reproduce the issue:
See sandbox: https://codesandbox.io/s/local-query-typepolicies-bug-s2ssq?file=/src/index.js
Instructions within, but at a high level - it seems to be the difference between applying type policies to the cache at creation vs applying type policies at a later time. I have tried to narrow down the sandbox as much as I could.
vs
Versions
The text was updated successfully, but these errors were encountered: