Skip to content

Default values for nested input objects #385

Closed
@eknkc

Description

@eknkc

Hi,

It seems that if a nested input object is not supplied, the default values are not applied either;

const SomeConfig = new GraphQLInputObjectType({
  name: "X",
  fields: {
    foo: { type: GraphQLInt, defaultValue: 0 }
  }
})

const Query = new GraphQLObjectType({
  name: "Query",
  fields: {
    someQuery: {
      type: GraphQLString,
      args: {
        bar: { type: SomeConfig, defaultValue: {} }
      },
      resolve(parent, args) {
       // if no bar is supplied and bar has no defaultvalue, args.bar is null, this is expected.
       // if bar arg has a defaultValue: {} as above
       // args.bar.foo is not populated, args becomes {}
      }
     }
  }  
});

How can I make sure that the entire nested argument graph is populated with their default values?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions