GatoGraphQL / GatoGraphQL

Interact with all your data in WordPress using GraphQL

Home Page:https://gatographql.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Consider passing the AST `asQueryString` to a GraphQL syntax formatter to add newlines

leoloso opened this issue · comments

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