-
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
Apollo Client omits fields from fragments on an interfaces #11624
Comments
Hi Mark, I'm looking at the reproduction and it doesn't seem to reproduce what you are describing here - could it be that you forgot pushing the final version of the reproduction to the repo? Right now, there are no fragments at all in that reproduction. That said, the behaviour you describe here roughly sounds like you might be missing |
@phryneas I accidentally committed my work-around -- whoops. I pushed the update. I took your advice and providing It seems like strange behavior given the information available to the client:
Can the client detect cases where it has insufficient information to complete a query, and issue warnings to the developer? |
Unfortunately, there are more complex cases where it would quickly become unpredictable if we were to just take the server answer. You could have something like const ExampleQuery = gql`
fragment ExampleFragmentA on InterfaceA {
__typename
id
name: fieldA
}
fragment ExampleFragmentB on InterfaceB {
__typename
id
name: fieldB
}
query {
exampleQuery {
__typename
...ExampleFragmentA
...ExampleFragmentB
}
}
`; The cache would need to save this in a normalized fashion. => We need the information which types implement which interfaces, or otherwise we'd end up with unpredictable behaviour. And since the Client has no knowledge of the Schema (it could be multiple megabytes big!), you have to tell it about those connections with I believe this should already trigger a warning. Did you increase the verbosity? import { setVerbosity } from "ts-invariant";
setVerbosity("debug"); |
That makes sense. Thank you for walking me through the problem. I did test |
Following up to say that this ticket can be closed. I'd love to see the client more proactively nudge developers impacted by this, but the problem and solution are covered by existing docs. |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue Description
Apollo Client strips fields from results when those fields were queried by way of a fragment on an interface. That's a mouthful, but the repro steps are simple and show it clearly. Note that this does not align with the behavior of apollo-server, which performs as I expect and returns everything for which I query.
I can work around this in two ways:
Related: #8898. I chose not to add to that ticket, as @phryneas already noted that it had become unclear, whereas this is a specific and reproducible bug.
Link to Reproduction
https://github.com/maslade/apollo-client-bug-reproduction
Reproduction Steps
npm install && npm start
http://localhost:8080
by default.Expected behavior
I see one item of type
ExampleInterface
, including its typename, ID, and name. When I immediatelylog the results of
useQuery
, they match what I see in the network tab. It looks like this:Actual behavior
I see one item with only a
__typename
field.Background
This occurs when querying for an interface using a fragment.
I can work around it by not (A) using fragments or (B) using a fragment for each subtype. Both
options are problematic.
Workaround A
Workaround B
@apollo/client
version3.9.5
The text was updated successfully, but these errors were encountered: