Skip to content

Can non-null fields have default values? #570

Open
@Yekut

Description

@Yekut

First issue and in general new to GraphQL in its current form, so apologies if this makes no sense. This is partially a question and partially a potential bug report -

Can non-null fields have default values? From looking at the spec it seems the answer is no, but some more direct clarification in the spec would be great (from https://facebook.github.io/graphql/June2018/#sec-Type-System.Non-Null) -

Inputs (such as field arguments), are always optional by default. However a non‐null input type is required. In addition to not accepting the value null, it also does not accept omission. For the sake of simplicity nullable types are always optional and non‐null types are always required.

The above seem to imply non-null fields cannot be omitted which makes default values useless, but it also didn't explicitly forbids default values.

Additionally, if indeed default values cannot be used in a non-null field, the grammar doesn’t require a default value to be attached to a non-null field (https://facebook.github.io/graphql/June2018/#sec-Field-Arguments). Would it be helpful to put this in the grammar?

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✏️ EditorialPR is non-normative or does not influence implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions