Is it possible to use inheritance with GraphQL input types?

Technology CommunityCategory: GraphQLIs it possible to use inheritance with GraphQL input types?
VietMX Staff asked 3 years ago

No, the spec does not allow input types to implement interfaces. And GraphQL type system in general does not define any form of inheritance (the extends keyword adds fields to an existing type, and isn’t for inheritance).

Better yet, you might be able to solve your problem via composition (always keep composition over inheritance in mind).

input Name {
  firstName: String
  lastName: String
}

input UserInput {
  name: Name
  password: String!
}

input UserChangesInput {
  name: Name
  id: ID!
  password: String
}