hasura / hasura/graphql-engine
Fragment definition should be allowed following the query that refers to it
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version:
2.11.0
### Environment
OSS
### What is the current behavior?
If a fragment is defined after the query which refers to it, the query fails to validate.
Example, this fails:
```graphql
query similar_briefs($sch_code: String!, $cli_code: String!, $pro_code: String!) {
briefs_for_schedule: briefly_brief(
where: {schedule_code: {_eq: $sch_code}})
{...brief_fields}
briefs_for_client_product: briefly_brief(
where: {
_and: [
{client_code: {_eq: $cli_code}},
{product_code: {_eq: $pro_code}},
{schedule_code: {_neq: $sch_code}}
]},
order_by: {time_saved: desc},
limit: 10)
{...brief_fields}
briefs_for_client: briefly_brief(
where: {
_and: [
{client_code: {_eq: $cli_code}},
{product_code: {_neq: $pro_code}},
{schedule_code: {_neq: $sch_code}}
]},
order_by: {time_saved: desc},
limit: 10)
{...brief_fields}
}
fragment brief_fields on briefly_brief {
__typename
id
schedule_code
client_desc
product_desc
time_saved
}
}
```
If the `fragment` is moved to the top, ahead of the queries that refer to it, then the query works as expected.
### What is the expected behavior?
The GraphQL specification and examples, suggest that it is valid to define the fragment after the query.
https://spec.graphql.org/June2018/#sec-Language.Fragments
### How to reproduce the issue?
1.
2.
3.
### Screenshots or Screencast
### Please provide any traces or logs that could help here.
### Any possible solutions?
### Can you identify the location in the source code where the problem exists?
### If the bug is confirmed, would you be willing to submit a PR?
### Keywords
Fragment
Contributor guide
Assessment
This issue has not been assessed yet.