-
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
Sub-selection without object reference #1415
Comments
@0x6e6562 Thanks for reporting the issue! I'm noticing that you're using a different fragment for writing vs. reading. Is that intentional? |
Good point! I'll re-test this using the same fragment to see if the behavior is the same. |
Interestingly if rewrite the code to re-use a common fragment definition, the error goes away. In this variant I can read from the cache, update some nodes on the fragment and then re-read the updated cache state back without an error: const fragment = gql`
fragment ev on liveEvents {
id
src
dst
since
state
user {
id
name
}
group {
id
name
}
}
`;
const data = client.readFragment({
id: '6247840904372038495',
fragment: fragment,
});
client.writeFragment({
id: '6247840904372038495',
fragment: fragment,
data: {
...data,
state: 'TAKE_UP',
user: {
id: '6247840904372038496',
name: 'Some name'
}
},
});
const cached = client.readFragment({
id: '6247840904372038495',
fragment: fragment,
}); This doesn't solve the issue I am seeing with my view component losing all of it's state after I invoke |
After a bit more debugging I've noticed that the |
OK, so I've gotten to the bottom of this. Because I've writing a sub node into the updated fragment with the
This scenario is not reported back the call stack. As a result, the The simple solution to this is to make sure that sub nodes have the appropriate @helfer I think we should close this issue because it is effectively user error. I'd do that now, except I'm not sure whether the |
The fact that the error is not reported well is definitely not great! I think that's really what this issue is about. |
Yep. Now that we expose functionality that was previously never accessible we need better errors. To summarize this issue, you can’t do this: client.writeQuery({
query: gql`
{ foo }
`,
data: {
foo: { a: 1, b: 2, c: 3 },
},
});
client.readQuery({
query: gql`
{ foo { a b c } }
`,
}); You need to write with the same query you are going to use for reading. So |
This will no longer be a silent error thanks to #1638, so I'm closing this. |
I'm trying the
writeFragment
API and I'm getting the following error that indicates I should file an issue:This is using 1.0.0-rc.2.
Intended outcome:
The updated client side cache should be available for reads in the same way that it is without attempting a write.
Actual outcome:
The non-updated client cache is readable but after issuing the write, the cache is no longer readable.
How to reproduce the issue:
First of all, the cache needs to get updated, e.g.:
The call to
writeFragment
completes successfully and the UI is updated, albeit not correctly.In order to debug the UI update bug, I tried to read the fragment I just previously wrote and this triggered the
sub-selection
error in the library:The text was updated successfully, but these errors were encountered: