0
votes

I have an input type that I want to use across multiple mutations. The only difference between its use from one mutation to another is the mandatory property of its fields.

Let's say for example that I have the following input type that I use in a create mutation:

input ObjectInput {
  name: String!
  description: String!
}

The name and description fields are both mandatory.

What if I want to use the same input type in another mutation where the description is optional? Do I really have to create another input type just to eliminate the mandatory property of the field?

1

1 Answers

2
votes

Do I really have to create another input type just to eliminate the mandatory property of the field?

Yes.

If there's more than the one field that's in common (same names, exact same types) between then you could break that out into a separate type that gets embedded into your input object type;

input ObjectIdentity {
  name: String!
}
input ObjectInput {
  identity: ObjectIdentity!
  description: String!
}

but that changes the object format (adds an extra "identity" object field) in a way you may not want.