-
Notifications
You must be signed in to change notification settings - Fork 2k
Default values for nested input objects #385
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
Comments
Thanks for bringing this up! Currently this indirect default values isn't supported, so you would have to manually write |
Thanks! I thought about writing a "extractDefault" function to create the default parameter for entire input object. Gonna need to call "getFields" on the input type to reflect on the inner fields and default values but getFields does not seem to be documented. Is it an internal API or safe to use? Ekin Koc On 9 May 2016 at 21:09:41, Lee Byron ([email protected](mailto:[email protected])) wrote:
|
any progress on this ?? it has been 2 years! |
Sorry for the delay. |
The closing of this feels a bit weird, did someone manage to open an RFC for that? |
It seems obvious to me that the And added it to the next GraphQL WG: https://github.com/graphql/graphql-wg/blob/master/agendas/2020-12-03.md#agenda |
In the mean time; here's a JS file that reproduces this issue: const {
graphqlSync,
printSchema,
GraphQLSchema,
GraphQLObjectType,
GraphQLInputObjectType,
GraphQLInt,
} = require("graphql");
const ExampleInputObject = new GraphQLInputObjectType({
name: "ExampleInputObject",
fields: {
number: {
type: GraphQLInt,
defaultValue: 3,
},
},
});
const Query = new GraphQLObjectType({
name: "Query",
fields: {
example: {
args: {
inputObject: {
type: ExampleInputObject,
defaultValue: {},
},
},
type: GraphQLInt,
resolve(source, args) {
return args.inputObject.number;
},
},
},
});
const schema = new GraphQLSchema({
query: Query,
});
console.log(printSchema(schema));
// All three of these should be equivalent?
const source = /* GraphQL */ `
query A {
example
}
query B {
example(inputObject: {})
}
query C {
example(inputObject: { number: 3 })
}
`;
const result1 = graphqlSync({ schema, source, operationName: "A" });
const result2 = graphqlSync({ schema, source, operationName: "B" });
const result3 = graphqlSync({ schema, source, operationName: "C" });
console.log(JSON.stringify(result1.data));
console.log(JSON.stringify(result2.data));
console.log(JSON.stringify(result3.data)); And you can fix it by changing line 28: type: ExampleInputObject,
- defaultValue: {},
+ defaultValue: coerceInputValue({}, ExampleInputObject), (also import |
Hi,
It seems that if a nested input object is not supplied, the default values are not applied either;
How can I make sure that the entire nested argument graph is populated with their default values?
The text was updated successfully, but these errors were encountered: