I get an error if I do something like this and the property doesn't exist:
client.readFragment({
id: 123,
fragment: gql`
fragment league on League {
name
}
`,
})
The error I get is:
Can't find field name on object (.....) {
"_id": 123,
"__typename": "League"
}.
Why is there an error if a field doesn't exist? It does exist in the schema, just not on the object in the Apollo cache.
@elie222 you cannot read partial data out of the Apollo store. The reason behind this is that we think it's very hard to reason about what data will be available in your UI component. It's much easier to do things if you either have a complete result or no result at all.
However, if you have a really good use-case, we can definitely revisit that decision.
So I'm a little confused how it's supposed to work. Why I am listing the
subfields at all when doing readFragment? And not just requesting the
document by id and receiving the entire document. The way things are now I
have to guess / keep track of what the shape of the document is at any
given time. Unless I'm missing something.
On 12 Apr 2017 21:50, "Jonas Helfer" notifications@github.com wrote:
@elie222 https://github.com/elie222 you cannot read partial data out of
the Apollo store. The reason behind this is that we think it's very hard to
reason about what data will be available in your UI component. It's much
easier to do things if you either have a complete result or no result at
all.However, if you have a really good use-case, we can definitely revisit
that decision.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/apollographql/apollo-client/issues/1579#issuecomment-293672804,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AC8oX6ICij-QReLF81MWm7cAaAWBr7GPks5rvRzegaJpZM4M7hjr
.
I see it in the docs now:
If all of the data needed to fulfill this read is in Apollo Client’s normalized data cache then a data object will be returned in the shape of the query you wanted to read. If not all of the data needed to fulfill this read is in Apollo Client’s cache then an error will be thrown instead, so make sure to only read data that you know you have!
Honestly this feels like a bad design decision, why throw an error instead of just returning null? Same way as graphql server would do.
Feels like this issue should be reopened.
Most helpful comment
I see it in the docs now:
Honestly this feels like a bad design decision, why throw an error instead of just returning null? Same way as graphql server would do.
Feels like this issue should be reopened.