graphql-go icon indicating copy to clipboard operation
graphql-go copied to clipboard

Additional fields on interface implementer do not set default values

Open tonyghita opened this issue 7 years ago • 0 comments

Expected behavior

Given the schema

interface Namer {
  name: String!
}

type User implements Namer {
  id: ID!
  name(type: NameType = FULL): String!
  email: String!
}

enum NameType {
  FULL
  FIRST
  LAST
}

type Query {
  namedThings: [Namer]
}

and the query

{
  namedThings {
     name
  }
}

I would expect the name field resolver to receive the default argument value for the argument type when the Namer being resolved is a User.

func (r *UserResolver) Name(args *struct{Type string}) string {
  switch args.Type {
   case "":
     panic("argument 'type' should have a value!")
   default:
     // the value was set, continue
  }

  return ""
}

Actual behavior

The value of the type argument is un-set. If the field resolver was written as above, the panic would be triggered.

Relevant links

tonyghita avatar Jan 26 '18 17:01 tonyghita