Skip to content
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

Passing null variable into fields with default argument #145

Open
bullno1 opened this issue Jan 4, 2018 · 3 comments
Open

Passing null variable into fields with default argument #145

bullno1 opened this issue Jan 4, 2018 · 3 comments

Comments

@bullno1
Copy link
Contributor

bullno1 commented Jan 4, 2018

Not sure if this is a bug or a feature.

Given the schema:

type Query {
  articles(includeDeleted: Boolean = false): [Article]
}

And the query:

query ListArticles($includeDeleted: Boolean) {
   articles(includeDeleted: $includeDeleted) { title }
}

Calling the query without providing $includeDeleted will result in null being passed into articles( i.e: articles(includeDeleted: null) while includeDeleted was specified to default to false. Changing the above query to:

query ListArticles($includeDeleted: Boolean = false) {
   articles(includeDeleted: $includeDeleted) { title }
}

will achieve the desired result but that's a repetition of default value.

GraphQL commit: 135657f745254198f3d07e35fd3a63623144b119

@jlouis
Copy link
Owner

jlouis commented Feb 21, 2018

This is actually an interesting case where I'd have to read the spec in order to understand exactly what is going on. I don't know the rules of how the expansion should proceed in this case. A rough guess is that if you don't provide $includeDeleted and that parameter has no default, then the default value of the field in the schema should take precedence.

I'll have to dig a bit in the spec to figure this one out as well, and then create a test case for it.

@jlouis
Copy link
Owner

jlouis commented Jun 22, 2018

Since Jun2018 spec, this is now a bug. The details are in #166, and we can clarify how resolution should happen. The spec now:

  • accepts not providing a parameter if there is a default value for the parameter in the schema, and it doesn't matter if the argument in which the parameter is used is non-null or nullable.

So this is a bug which hinges on us becoming Jun2018 spec compliant (which we currently aren't. A couple of smaller things are missing).

@jlouis
Copy link
Owner

jlouis commented Jun 25, 2018

Update: This is also affected by #180 which determines in detail how null values can be passed from the client to the server.

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

2 participants