Sub queries returning the same data when they should be different
See original GitHub issueI’m running in to an issue only in the Apollo client that I’m troubleshooting. If you could point me how I could best debug this I’d be very happy.
Intended & outcome: Below is the sample query, the GraphiQL results (which is the expected results), the apollo results (the actual outcome of the Apollo client, which is incorrect), and my node unit test as well. This exact query works fine in GraphiQL but is incorrect in Apollo.
You’ll notice the “sum” amount, with the Apollo results, is the same for all sub queries. Contrast that with the GraphiQL results (expected results) and you’ll notice they are all different. It seems like Apollo is getting the last sub query results for user.* and populating all of them with those last values.
I’ve verified this happens in the Apollo client in our Node app and in our React app. I’ve also verified that the GraphQL server is indeed returning the correct raw results.
Another interesting data point: If I set client.addTypename = false;
, then it will properly return the results. Obviously I don’t want to do that as it will throw all sorts of warnings such as:
You're using fragments in your queries, but either don't have the addTypename: true option set in Apollo Client, or you are trying to write a fragment to the store without the __typename. Please turn on the addTypename option and include __typename when writing fragments so that Apollo Client can accurately match fragments. Could not find __typename on Fragment ContributionData
and DEPRECATION WARNING: using fragments without __typename is unsupported behavior and will be removed in future versions of Apollo client. You should fix this and set addTypename to true now.
https://gist.github.com/rblalock/e012a6a2096ead584f396bcf36584fdc
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
Ok my apologies, I had the option in the wrong spot (under the networkInterface options).
dataIdFromObject: () => undefined,
does indeed work under the top level options for the apollo client. Thanks for helping me with this.Ok, glad you figured it out! 🙂