graphql / graphql/graphql-spec

Can non-null fields have default values?

Open
#570 3 comments 6 reactions 0 assignees View on GitHub
✏️ Editorial 💤 stale ?
Dominant language
JavaScript
Stars
14.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.