Skip to content

Default values for Non Null types #1405

Closed
@benwaffle

Description

@benwaffle

When supplying a default value for a required field, it is not used and instead throws a validation error.

const { graphql, buildSchema } = require('graphql')

const schema = buildSchema(`
type Query {
  hello(x: Int! = 42): Int
}
`)

const root = {
  hello: (args) => args.x
}

graphql(schema, '{ hello }', root).then(console.log)

Produces:
GraphQLError: Field "hello" argument "x" of type "Int!" is required but not provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions