Search code examples
javagraphqlgraphql-java

graphql-java variable mandatory (required) in programmatically created schema


I'm new to GraphQL and graphql-java. I'm trying to create this schema programmatically

type Query{name:String!}

I don't know how to make the name field not being null String! By default this is optional.

GraphQLObjectType queryType = GraphQLObjectType.newObject()
        .name("Query")
        .field(GraphQLFieldDefinition.newFieldDefinition()
                .name("name")
                .type(Scalars.GraphQLString)
                .dataFetcher(new StaticDataFetcher("Joe")))
        .build();

Solution

  • .type(GraphQLNonNull.nonNull(Scalars.GraphQLString))