Skip to content

Validator does not catch missing value parameters #308

Closed

Description

@scf37

if declared hello with (a: string, b: string) following will pass execution successfully:
{hello(a: "4")}
{hello(b: "4")}
{hello}

code (sorry for Scala):

val queryType = newObject()
        .name("helloWorldQuery")
        .field {
          newFieldDefinition()
            .`type`(GraphQLString)
            .name("hello")
            .argument {
              GraphQLArgument.newArgument()
                    .name("a")
                  .description("description")
                  .`type`(GraphQLString)
                  .build()
            }
            .argument {
              GraphQLArgument.newArgument()
                  .name("b")
                  .description("description")
                  .`type`(GraphQLString)
                  .build()
            }
            .dataFetcher(env => "world")
        }
    .build()

    val schema = GraphQLSchema.newSchema()
        .query(queryType)
        .build()

    val graphQL = new GraphQL(schema)

    val result = graphQL.execute("{hello(a: \"4\")}")
    System.out.println(result.getData)
    System.out.println(result.getErrors)

Activity

  1. bbakerman commented on Jan 30, 2017

    @bbakerman
    Member

    Can you expand more on what your expectations are here?

    I think your are right in that the spec says 👍

    http://facebook.github.io/graphql/#sec-Validation.Arguments

    that arguments with a non null "type" should not allowed to be non null at runtime.

  2. scf37 commented on Jan 30, 2017

    @scf37
    Author

    I expected error about missing arguments.
    Does nullable type of field argument imply default value of null?

  3. bbakerman commented on Jan 30, 2017

    @bbakerman
    Member

    I think I have it wrong. The library requires you to wrap the type in a GraphQLNonNull type first

    so

     new GraphQLNonNull(GraphQLString)
    

    Thats the equivalent of the JS implementation where you use !

    rollDice(numDice: Int!, numSides: Int): [Int]
    

    So by default the Java API assumes its not required

  4. bbakerman commented on Jan 30, 2017

    @bbakerman
    Member

    GraphQLNonNull should have a factory for static import so you could do

     GraphQLNonNull.nonNull(GraphQLString)
    

    and hence

     .name("a")
     .type(nonNull(GraphQLString))
    
  5. added 4 commits that reference this issue on Jan 30, 2017
  6. okorz001 commented on Feb 10, 2017

    @okorz001
    Contributor

    It seems this issue could be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions