question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

addTypename set to true does not add __typename to root selection set

See original GitHub issue

Intended outcome:

I am using InMemoryCache with addTypename set to true (the default). I expected __typename to be added to all selection sets in my query, including the root selection set.

Actual outcome:

__typename is added to all selection sets, but not the root object.

Because of this, the store defaults to “Query” as __typename for the root query object. My root query object is actually called “query_root”, and thus my type policy field settings for that object are not found during cache reads, even though I set queryType: true on the “query_root” definition.

Adding __typename explicitly to the root selection set of my queries works around this issue, but doesn’t it make sense for it to be added automatically when addTypenames is enabled?

How to reproduce the issue:

Create a client with an InMemoryCache that has addTypename set to true. Observe that __typename is not added to root selection sets.

Versions

@apollo/client@3.3.0-rc.0

System: OS: macOS 10.15.4 Binaries: Node: 15.1.0 - /usr/local/bin/node Yarn: 1.22.10 - ~/dev/pony/src/front/node_modules/.bin/yarn npm: 7.0.8 - /usr/local/bin/npm Browsers: Chrome: 86.0.4240.198 Firefox: 81.0 Safari: 13.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
dminkovskycommented, Nov 25, 2020

Thank you @benjamn. I searched the codebase and somehow missed that.

Time is suddenly not on my side, but I will keep this in mind. Should be a fun exercise. Thanks again.

0reactions
hwillsoncommented, May 31, 2021

Let us know if this is still a concern with @apollo/client@latest - thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring the Apollo Client cache - Apollo GraphQL Docs
The cache usually obtains __typename information by adding the __typename field to every query selection set it sends to the server. It could...
Read more >
Configuring the cache - Client (React) - Apollo GraphQL Docs
addTypename, boolean. If true , the cache automatically adds __typename fields to all outgoing queries, removing the need to add them manually.
Read more >
Store error: the application attempted to write an object with no ...
After mutation when I am updating the cache, changes are reflected in UI but getting the below error. Invariant Violation ...
Read more >
Unit Tests with Enzyme and Apollo Graphql
In this third part we will add unit tests to our components and our resolvers. ... toBe(5); }); it('should set the unit price...
Read more >
A Guide to Unit Testing React Apollo Components - DoltHub
I initially had not added __typename s to the fragments in our mocks, thinking that adding addTypename={false} to MockedProvider was a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found