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.

Fragment is never used

See original GitHub issue

Response from graphql server is: Fragment "___profile___requestIndex_1___userPhotoThumb" is never used. But the problem is in the apollo-client 😦

I have next query via graphql decorator:

  query profile($slug: String!) {
    viewer {
      id,
    }
    user(slug: $slug) {
      id,
      ...userPhotoThumb,
    }
  }

On the server side rendering everything works fine. But when I try to continue on the client side I will get next response from graphql:

{
  "errors": [
    {
      "message": "Fragment \"___profile___requestIndex_1___userPhotoThumb\" is never used.",
      "locations": [
        {
          "line": 16,
          "column": 1
        }
      ]
    }
  ]
}

The problem is that request from apollo-client is

"query ___composed {
  ___profile___requestIndex_1___fieldIndex_0: viewer {
    id
    __typename
  }
  ___getViewer___requestIndex_2___fieldIndex_0: viewer {
    id
    __typename
  }
}

fragment ___profile___requestIndex_1___userPhotoThumb on User {
  ___profile___requestIndex_1___fieldIndex_1: picture
  ___profile___requestIndex_1___fieldIndex_2: slug
  ___profile___requestIndex_1___fieldIndex_3: __typename
}
"

As you can see “user” part is completely missing in the profile query. I think that user part is cached from server side rendering

Here is a complete graphql request

{
    "debugName": "___composed",
    "query": "query ___composed {\n  ___getViewer___requestIndex_0___fieldIndex_0: viewer {\n    id\n    __typename\n  }\n  ___profile___requestIndex_1___fieldIndex_0: viewer {\n    id\n    __typename\n  }\n  ___getViewer___requestIndex_2___fieldIndex_0: viewer {\n    id\n    __typename\n  }\n}\n\nfragment ___profile___requestIndex_1___userPhotoThumb on User {\n  ___profile___requestIndex_1___fieldIndex_1: picture\n  ___profile___requestIndex_1___fieldIndex_2: slug\n  ___profile___requestIndex_1___fieldIndex_3: __typename\n}\n",
    "variables": {
        "___profile___requestIndex_1___slug": "zlatko-fedor"
    }
}

I have tried apollo-client 0.4.19 and 0.4.20 with same results. In this moment I am not able to use fragments anymore. Please help me to fix this issue. Thank you very much

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
seedencommented, Oct 19, 2016

I can confirm it is fixed in the 0.5.0-1

1reaction
helfercommented, Oct 11, 2016

@seeden ah, ok, makes sense. It’s exactly what you suspected. We removed the query diffing functionality, so the next version won’t contain that bug any more 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fragment "X" is never used. Suggest: warning instead of error.
This is actually an error from your GraphQL server - it's running validation on the query and that's a default validation rule for...
Read more >
Fragments - Apollo GraphQL Docs
A GraphQL fragment is a piece of logic that can be shared between multiple queries and mutations. Here's the declaration of a NameParts...
Read more >
ApolloError: Fragment was used, but not defined
I manually call client.query to fetch the latest data on click of the button, but it throws an error saying it can't find...
Read more >
GraphQL fragments explained - LogRocket Blog
A GraphQL fragment is a reusable part of the query. In GraphQL, you may run into situations where ... Benefits of using a...
Read more >
Using Fragments – Angular - GraphQL Code Generator
Using Fragments. A GraphQL fragment is a shared piece of query logic. ... There are two principal uses for fragments in Apollo:.
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