grooviter / gql

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

NonNull constraints are not working #12

Closed mariogarcia closed 7 years ago

mariogarcia commented 7 years ago

When trying to expose the following input type:

static final GraphQLInputObjectType GraphQLMealInputEntry = DSL.input('MealEntryInput') {
    description 'every dish or ingredient in a given meal'

    field 'description', nonNull(GraphQLString)
    field 'quantity', nonNull(GraphQLFloat)
    field 'unitType', nonNull(GraphQLUnitType)
  }

It gives me the following stacktrace:

Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'GraphQLNonNull{wrappedType=GraphQLScalarType{name='String', description='Built-in String', coercing=graphql.Scalars$8@2629d5dc}}' with class 'graphql.schema.GraphQLNonNull' to class 'graphql.schema.GraphQLScalarType'
    at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
    at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
    at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
    at gql.health.back.food.Types$__clinit__closure3.doCall(Types.groovy:37)
    at gql.health.back.food.Types$__clinit__closure3.call(Types.groovy)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:242)
    at gql.DSL.input(DSL.groovy:180)
    at gql.health.back.food.Types.<clinit>(Types.groovy:34)

It seems that, because fields in DSL.input only expect to receive or a GraphQLInputType or a GraphQLScalarType they doesn't know anything about a GraphQLNonNull type.

Maybe it's necessary to overwrite field with the following version:

FieldBuilder field(String name, GraphQLNonNull nonNullType)
mariogarcia commented 7 years ago

I've found inconsistencies in object type null/list calls. It turns out that a scalar type is both input and output type, and the same goes for nonNull/list types. So basically I only need: