Skip to content
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

HeuristicFragmentMatcher enforces __typename on ROOT_QUERY #4488

Closed
dulakm opened this issue Feb 24, 2019 · 1 comment
Closed

HeuristicFragmentMatcher enforces __typename on ROOT_QUERY #4488

dulakm opened this issue Feb 24, 2019 · 1 comment

Comments

@dulakm
Copy link

dulakm commented Feb 24, 2019

Intended outcome:
When using Fragment on Query warning is not shown and query is executed.

Actual outcome:
When I use query including Fragment defined on Query, HeuristicFragmentMatcher fails on checking the store as ROOT_QUERY doesn't contain __typename.

Stacktrace: https://gist.github.com/dulakm/6ee9d6afb7a730a38bab714875bd3540

How to reproduce the issue:

  1. Firstly, make some query, that doesn't contain any fragments. In my scenario, this is the query:
    1.  query GetUserConfig($scope: String!) {
           configs(configsFilter: {
               scopeIs: $scope
           }) {
               id,
               data
           }
       }
      
    2. As roots are not appended with __typename (Don't add fields to the root mutation/query #463) what ends up in cache is this: {"data":{"configs":[{"id":"SOME_ID","data":"SOME_DATA","__typename":"Config"}]}}. Data have its __typename however as expected, ROOT_QUERY doesn't.
  2. Secondly, let's make query containing some fragment. In my case:
    1.  query SomeQuery {
           ...EnumsFragment
       }
      
       fragment EnumsFragment on Query {
           supportedOptions {
               name
           }
       }
      
    2. Now in this very exact moment the warning happens (attached stacktrace) and the query is prevented from being sent to server. When debugging the issue what I have found out:
      1. Fragment matcher is called by readFromStore.js#153
      2. Basic look at the parameters:
      rootValue
      {type: "id", id: "ROOT_QUERY", generated: true, typename: "Query"}
      typeCondition
      "Query"
      contextValue
      {store: DepTrackingCache, dataIdFromObject: ƒ, cacheRedirects: {…}}
      
      1. fragmentMatcher.js#13 gets object which is in fact ROOT_QUERY (the one from step 1.)
      2. It passes checks on lines 14 and 17
      3. On line 20 it is affirmed that ROOT_QUERY doesn't contain __typename and warning is thrown.

Versions

  System:
    OS: Windows 10
  Binaries:
    Node: 8.10.0 - C:\Applications\nodejs\node.EXE
    Yarn: 1.13.0 - C:\Users\moro\AppData\Roaming\npm\yarn.CMD
    npm: 6.7.0 - C:\Applications\nodejs\npm.CMD
  Browsers:
    Edge: 42.17134.1.0
  npmPackages:
    apollo-cache-inmemory: 1.3.12 => 1.3.12
    apollo-client: 2.4.8 => 2.4.8
    apollo-link: 1.2.6 => 1.2.6
    apollo-link-context: 1.0.12 => 1.0.12
    apollo-link-error: 1.1.5 => 1.1.5
    apollo-link-http: 1.5.9 => 1.5.9
    react-apollo: 2.3.3 => 2.3.3
@hwillson
Copy link
Member

Fragment matchers have been replaced by possibleTypes. Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants