apollo-client: Query containing only fragments does not work
Intended outcome: Trying to query using fragments, using a query like:
const frag = gql`
fragment peopleFrag on Query {
people {
id
name
}
}
`;
const query = gql`
query ErrorTemplate {
...peopleFrag
}
${frag}
`
Actual outcome: The query never gets sent to the graphql server
How to reproduce the issue: I reproduced this using the react-apollo-error-template. Just replace the query in App.js with:
const frag = gql`
fragment peopleFrag on Query {
people {
id
name
}
}
`;
export default graphql(
gql`
query ErrorTemplate {
# people {
# id
# }
...peopleFrag
}
${frag}
`
)(App);
If you uncomment the three lines above, the query will work.
Version
- apollo-client: 2.0.1
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 22 (10 by maintainers)
Anyone please provide fix for this issue I am also facing the same.
I am testing out
apollo-client
3.0.0-beta
and it doesn’t seem to call a query that only contains a fragment, seems like a regression?My issue is that it doesn’t see a second fragment that I created, saying the fragment doesn’t exist. I just moved the fragment definition to an inline non gql string:
Maybe it’s a little less performant, but it works.
Is there any plan to fix this? It seems to me like a pretty serious issue resulting in unexpected bugs that are extremely difficult to trace. Appreciate any help here! 😃
My peopleFrag is a fragment on Query, which, from my understanding, is a type. So it seems I am adhering to the GraphQL spec. Or am I mistaken?