Skip to content

GraphQL playground: Warning "<value> is required but not provided" although it has a default value #1299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
roschaefer opened this issue Dec 28, 2020 · 0 comments

Comments

@roschaefer
Copy link

Hey folks,

I hope this is the right repository to open issues for ApolloServer's playground. I've read this announcement and I assume this is the right location. Furthermore I searched in this repository for "is required" and "not provided" but couldn't find the relevant line of code. Feel free to redirect me if this is not the right repository.

Problem

GraphQL Playground shows a warning if a non-nullable field with a default value was not provided.

See this issue: graphql/graphql-spec#570

Expected

No warning.

Actual

Field <query> argument <field> of type <type>! is required but not provided.

It seems to be valid GraphQL to assign a default value to a non-nullable field. In fact, the wording of GraphQL playground is misleading: The bang ! marks a field as non-nullable but not as required. I suggest to rephrase the warning as such:

Field <query> argument <field> of type <type>! is non-nullable but not provided.

If a field is marked as non-nullable and has a default value, you can omit the field but cannot assign null as a value.

2020-12-28_15-50

Context

I ran into this issue while working with GraphQL Schema Stitching and using GraphQL playground on a remote GraphQL schema which has a non-nullable field with a default value. For context, here is the conversation with a maintainer of the GraphQL remote API:

roschaefer Yesterday at 7:06 PM
Hey Friends!
I'm using the freshly renovated GraphQL Schema Stitching API along with GraphCMS: https://www.graphql-tools.com/docs/stitch-combining-schemas
Can you please explain to me why GraphCMS defines input arguments for all queries and mutations called stage and locales, makes them required with a bang ! but assigns a default value?

stage: Stage! = DRAFT
locales: [Locale!]! = [en]

In my opinion, a default value is contradictory to a required argument with a !.
The problem is that a local ApolloServer playground will show a warning if I do not fill out those input arguments. With GraphQL Schema Stitching the playground will make a request to the remote GraphQL endpoint for schema introspection. Nevertheless, running the query or the mutation works just fine without those arguments.
2020-12-27_19-04.png
2020-12-27_19-04.png

white_check_mark
eyes
raised_hands

21 replies

roschaefer 20 hours ago
2020-12-27_19-08.png
2020-12-27_19-08.png

maintainer 4 hours ago
Hey there! The default values are set per default locale and per selected default delivery stage on the public api permissions or of you use a token where your default delivery stage is for example PUBLISHED, this will be your default value also in the schema.

maintainer 4 hours ago
I will raise this thread in our internal slack

maintainer 4 hours ago
Reply: The playground he is using seems to not handle graphql schema defaults. This is the secrion in the spec: http://spec.graphql.org/draft/#sec-Field-Arguments

roschaefer 2 hours ago
@maintainer thank you for your reply. I know that GraphCMS sets default values, in my case its:
stage: Stage! = DRAFT
locales: [Locale!]! = [en]

roschaefer 2 hours ago
I also understand how default values work in general. ApolloServer playground handles them just fine

roschaefer 2 hours ago
I'm specifically asking why do you make input values required with a bang AND set a default value

roschaefer 2 hours ago
☝️ this does not make sense in my opinion

roschaefer 2 hours ago
Either you have a default value OR it is required

roschaefer 2 hours ago
2020-12-28_14-05.png
2020-12-28_14-05.png

maintainer 1 hour ago
It's simply convenience as you can override the defaults globally on token level

roschaefer 1 hour ago
Yes, I like defaults. Not saying anything against defaults. I'm confused why those input arguments are marked as "required" if they, in fact, are not required.

roschaefer 1 hour ago
The bang marks the input arguments as required

roschaefer 1 hour ago
that's why I'm asking: Why don't you just remove the bang? (Also asking myself: Why is it even possible to require values and not require them at the same time?)

maintainer 41 minutes ago
If they would not be required, you could override the default with null

maintainer 41 minutes ago
And that wouldn't work in resolving

roschaefer 37 minutes ago
ahh, that's exactly the answer that explains it to me - thanks!

roschaefer 34 minutes ago
I'm going to research a little to understand if that's what people do as a convention and if maybe ApolloServer playground could be improved to account for that

roschaefer 32 minutes ago
bingo: graphql/graphql-spec#570

GitHubGitHub
Can non-null fields have default values? · Issue graphql/graphiql#570 · graphql/graphql-spec
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 defa...

roschaefer 32 minutes ago
so I should change my own conception in my brain, bang doesn't mean "required" but "non-nullable"

roschaefer 31 minutes ago
makes sense now

2020-12-27_19-08
2020-12-27_19-04
2020-12-28_14-05

@acao acao transferred this issue from graphql/graphiql Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant