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.

Nested fragments throw heuristic fragment matching errors

See original GitHub issue

Intended outcome:

Was trying to nest inline fragments into another fragment or use an interface, or union. Got an error about heuristic fragment matching.

Actual outcome:

When using nested fragments, unions or interfaces, InMemory will throw a heuristic fragment matching error:

WARNING: heuristic fragment matching going on!
fragment CharacterFields on Character {
  ... on Droid {
    primaryFunction
  }
  ... on Human {
    height
  }
}

query {
  characters {
    ...CharacterFields
  }
}

This works:

query {
  characters {
    ... on Droid {
      primaryFunction
    }
    ... on Human {
      height
    }
  }
}

How to reproduce the issue:

https://github.com/ledenis/apollo-introspection-fragment-matcher-issue

Versions

  System:
    OS: macOS 10.15
  Binaries:
    Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
    Yarn: 1.16.0 - ~/.nvm/versions/node/v10.16.0/bin/yarn
    npm: 6.11.3 - ~/.nvm/versions/node/v10.16.0/bin/npm
  Browsers:
    Chrome: 77.0.3865.90
    Firefox: 68.0.2
    Safari: 13.0.2
  npmPackages:
    apollo-angular: 1.7.0 => 1.7.0 
    apollo-angular-link-http: 1.8.0 => 1.8.0 
    apollo-angular-link-persisted: 1.1.0 => 1.1.0 
    apollo-cache-inmemory: 1.6.3 => 1.6.3 
    apollo-cache-persist: 0.1.1 => 0.1.1 
    apollo-client: 2.6.4 => 2.6.4 
    apollo-link: 1.2.13 => 1.2.13 
    apollo-link-context: 1.0.19 => 1.0.19 
    apollo-link-error: 1.1.12 => 1.1.12 
    apollo-link-http: 1.5.16 => 1.5.16 
    apollo-link-ws: 1.0.19 => 1.0.19 
    apollo-server-core: 2.9.5 => 2.9.5 
    apollo-server-testing: 2.9.5 => 2.9.5

Related: https://github.com/apollographql/apollo-client/issues/3397 Partial temporary workaround (doesn’t work at all for interfaces):

const fragmentMatcher = new IntrospectionFragmentMatcher({
  introspectionQueryResultData: {
    __schema: {
      types: []
    }
  }
});

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:33
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
RudiPerssoncommented, Mar 2, 2020

@chandan-reddy-k

This problem was in existence from previous versions of apollo but the latest version ideally shouldn’t throw this warning. I solved this by fetching the entire schema into application. I wrote a detailed blog on this, Check it out:

https://medium.com/@chandan.reddy/whats-going-on-with-the-heuristic-fragment-matcher-in-graphql-apollo-client-e721075e92be

This fixed the problem for me, but just passing an empty array also works. Why fetch the schema ??

2reactions
chandan-reddy-kcommented, Dec 27, 2019

This problem was in existence from previous versions of apollo but the latest version ideally shouldn’t throw this warning. I solved this by fetching the entire schema into application. I wrote a detailed blog on this, Check it out:

https://medium.com/@chandan.reddy/whats-going-on-with-the-heuristic-fragment-matcher-in-graphql-apollo-client-e721075e92be

Read more comments on GitHub >

github_iconTop Results From Across the Web

Heuristic Fragment matcher warning! How to fix it?
Error : You are using the simple (heuristic) fragment matcher, but your queries contain union or interface types. Should you worry about this?...
Read more >
Fragments - Apollo GraphQL Docs
A GraphQL fragment is a piece of logic that can be shared between multiple queries and mutations. ... Every fragment includes a subset...
Read more >
[Solved]-How to build GraphQL schema for reverse lookup ...
WARNING: heuristic fragment matching going on!. It seems this is a bug (github issue). In order to fix it, in Apollo settings we...
Read more >
Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
Read more >
@apollo/client | Yarn - Package Manager
Fix error thrown by nested keyFields: ["a", ["b", "c"], "d"] type policies when writing ... Bring back an improved form of heuristic fragment...
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