Use fragments of different types in query
See original GitHub issuehey 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:
- Created 7 years ago
- Comments:7 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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
andname
directly.Sorry guys, the problem sat in front of the PC. I had done some huge mistakes with the query building.