-
-
Notifications
You must be signed in to change notification settings - Fork 677
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
@Arg defaultValue "null" seems not to be recognized #593
Comments
@karladler Can you reproduce the default |
@MichalLytek Yes, default A graphql-js example where null arguments are valid: https://repl.it/repls/ClearcutRaggedFormat const { graphql } = require('graphql');
const { makeExecutableSchema } = require('graphql-tools');
const typeDefs = `
type Query {
hello(msg: String = null): Boolean
}
`;
const resolvers = {
Query: {
hello: (_, args) => {
console.log(args); // --> { msg: null }
return true;
},
},
};
const schema = makeExecutableSchema({ typeDefs, resolvers });
const query = `
query {
a: hello
b: hello(msg: null)
}
`;
graphql(schema, query) |
And what is the practical difference between: hello(msg: String = null) and hello(msg: String) 🤔 In both cases if argument is not provided, it gonna be null/undefined, and from client perspective the arg is optional. |
Is default But, an explicit |
But there is no such distinction in GraphQL Specification between null and undefined and nothing about the implicit undefined behavior when value not provided and explicit null when null provided. It's just a case in JS where we have two empty values representation. |
Ok, I stand corrected. Semantically there is a difference, but like @MichalLytek said, the spec states that we should not treat implicit and explicit null differently. |
More context: So, if With |
so |
Closing as |
Describe the bug
Setting the defaultValue like explicitly to
null
in @Arg('id', { defaultValue: null })
seems not to be applied, when omitting the argumentid
on request.To Reproduce
Logs
id undefined
;Expected behavior
Logs
id null
; when requested without arguments.Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: