grooviter / gql

Groovy GraphQL library
http://grooviter.github.io/gql/
Apache License 2.0
49 stars 6 forks source link

Use query alias as GraphQL specification #1

Open mariogarcia opened 7 years ago

mariogarcia commented 7 years ago

At the moment the alias is added as a method call at the end of the query:

import gql.DSL

def result = DSL.execute(schema) {
  query('byYear', [year: '1962']) {
    returns(Film) {
      title
      year
    }
    alias 'first'
  }

  query('byYear', [year: '2015']) {
    returns {
      title
      year
      bond
    }
    alias 'last'
  }
}

It would be great to use statement labels as query alias. Something like this:

import gql.DSL

def result = DSL.execute(schema) {
  first: query('byYear', [year: '1962']) {
    returns(Film) {
      title
      year
    }
  }

  last: query('byYear', [year: '2015']) {
    returns {
      title
      year
      bond
    }
  }
}

That I think should involve an AST transform.