Ask questionsDefault values in default value of input types
Describe the Bug When defining a default value for an input type, its default values are not applied. I am not sure if its a problem of type-graphql or graphql-js.
To Reproduce
@InputType()
class MyInput {
@Field(() => Int, { defaultValue: 30 })
public take!: number;
}
@Resolver()
class MyResolver {
@Query(() => Boolean)
public myQuery(@Arg('arg', { defaultValue: {} }) arg: MyInput): boolean {
console.log(arg);
return true;
}
}
{
myQuery
}
with this query the log output is {}
Expected Behavior
the log output should be {take:30}
Environment (please complete the following information):
Answer
questions
backbone87
@croossin i solved it by reusing the default value of the "parent" input object:
const DEFAULT_FOO = { bar: 0 };
@InputType()
class FooInput {
@Field({ defaultValue: DEFAULT_FOO.bar })
public bar!: number;
}
@InputType()
class MyInput {
@Field({ defaultValue: DEFAULT_FOO })
public foo!: FooInput;
}
Related questions