Mutation Input and Payload Structure in GraphQL

InstructorNik Graf

Share this video with your friends

Send Tweet

Relay comes with a specification and a set of well define conventions for GraphQL Mutations. By following the conventions, we not only design Mutations in a way that they can be extended with easy, but also reduce a lot of cognitive overhead.

We can summarise the conventions into 5 rules:

  1. Mutations are named as verbs createProduct, introduceShip, deleteCollection.
  2. There must be a single argument input
  3. The input type name is the capitalised mutation name with a Input postfix e.g. CreateProductInput, IntroduceShipInput.
  4. The returned value is a new custom type that can contain various fields.
  5. The return type is name is the capitalized mutation name with a Payload postfix e.g. CreateProductPayload, IntroduceShipPayload.