Consider passing the AST `asQueryString` to a GraphQL syntax formatter to add newlines
leoloso opened this issue · comments
Leonardo Losoviz commented
Continuation of PR #1482.
Currently, the GraphQL query printed in each AST element's asQueryString
is formatted as a single line:
query FilterPosts($ids: [ID!]!) { posts(ids: $ids) { id title } }
Ideally, it should be formatted using line breaks:
query FilterPosts($ids: [ID!]!) {
posts(ids: $ids) {
id
title
}
}
Newlines are currently being added to separate fragments and operations:
query { test { ...userDataFragment } }
fragment userDataFragment on User { id name email }
Task: Consider if passing this output to a GraphQL syntax formatter to add the newlines is worth it and, if so, do it.
Benefits:
- The GraphQL query will be prettier, more understandable
Drawbacks:
- The query in a single line is better for debugging.
Can also consider the middle way: pass parameter $pretty: bool
to asQueryString
:
$pretty: false
<= single line$pretty: true
<= return through formatter