grooviter / gql

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

Default value for arguments #32

Closed KraftNSK closed 1 year ago

KraftNSK commented 4 years ago

Hi! The graphql supports the default values for the arguments, but this is not the case in this DSL (which sometimes is very distracting).

It is also unclear how to manage the mandatory parameters in dsl (analogue '!')

Thanks!

mariogarcia commented 4 years ago

True && True

    GraphQLInputObjectType MailFilterType = DSL.input('MailFilter') {
      field 'from', nonNull(GraphQLString)
      field 'to', nonNull(GraphQLString)
    }

Thanks for the feedback :+1:

mariogarcia commented 4 years ago

I'm realizing graphql-java v14.0 doesn't support default values when using variable references. For example having a query definition like this one:

type Query {
    hello(name: String = "amigo"): String
}

When you avoid passing the name argument, works as expected:

{
   sayHello
}

It returns hello amigo

But if you use a variable reference structure:

query SayHello($name:String){
    hello(name: $name)
}

it returns hello null

The problem is, that, in my experience the latter is the most common way of calling a GraphQL API from a frontend application.

I'm thinking of adding an issue to graphql-java to change this behavior and use the default value also for variable references, but in the meantime adding the default value to the DSL and the current behavior is the best I can do.

Can you give me some feedback on this @KraftNSK ?

mariogarcia commented 4 years ago

Added issue 1870 to graphql-java

mariogarcia commented 1 year ago

Fixed in graphql-java