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.

Use fragments of different types in query

See original GitHub issue

hey guys, I am trying to use fragments for different types together like this:

const subjectInfo = createFragment(gql`
  fragment subjectInfo on Subject {
    id
    name
  }`
)
const businessAreaInfo = createFragment(gql`
  fragment businessAreaInfo on BusinessArea {
    id
    name
    subjects {
      ...subjectInfo
    }
  }`,
  [subjectInfo]
)
graphql(gql`
query {
  businessAreas {
    ...businessAreaInfo
  }
}
`, {
  fragments: businessAreaInfo
})

but the resulting query, that Apollo sends to the server, looks like this:

{
  businessAreas {
    ...businessAreaInfo
    ...subjectInfo
  }
}

fragment businessAreaInfo on BusinessArea {
  id
  name
  subjects {
  ...subjectInfo
  }
}

fragment subjectInfo on Subject {
  id
  name
}

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
helfercommented, Oct 11, 2016

@jbreckel we’ll publish the next release this week, but because of the version bump it may take a few days for react-apollo to be updated as well.

In the meantime, a workaround would be to not use the subjectInfo fragment inside businessAreaInfo, and instead include the fields id and name directly.

0reactions
jbreckelcommented, Oct 17, 2016

Sorry guys, the problem sat in front of the PC. I had done some huge mistakes with the query building.

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 of...
Read more >
GraphQL fragments explained - LogRocket Blog
A GraphQL Fragment is a reusable unit of a GraphQL query, which creates a shared piece of query logic. The components of a...
Read more >
Query all fragments of type - Stack Overflow
Using a fragment spread on both i get access to their common field. Is their a way of merging them and using one...
Read more >
How to query your schema with GraphQL fragments - Medium
Inline fragments are useful for queries in which we have to resolve the type at runtime. We also use inline fragments when we...
Read more >
Communicating with fragments - Android Developers
The recommended option depends on the use case. To share persistent data with any custom APIs, you should use a ViewModel . For...
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