Skip to content

Latest commit

 

History

History
62 lines (52 loc) · 1.63 KB

README.md

File metadata and controls

62 lines (52 loc) · 1.63 KB

@jcm/nexus-plugin-relay-mutation

Patreon Logo
Discord Logo

This plugin adds the field method relayMutation(fieldName, fieldConfig) to the Nexus Schema Builder, which can be used to create Relay-compliant mutations.

It's based on the mutation helper from graphql-relay.

Sample usage:

const mutation = mutationField((t) => {
  t.relayMutation('addNumbers', {
    inputFields(t2) {
      t2.int('number1', {
        required: true,
      })
      t2.int('number2', {
        required: true,
      })
    },
    outputFields(t2) {
      t2.int('result')
    },
    mutateAndGetPayload(_root, input, _ctx, _info) {
      return {
        result: input.number1 + input.number2,
      }
    },
  })
})

With the above code, the following schema will be generated:

input addNumbersInput {
  number1: Int!
  number2: Int!
  clientMutationId: String
}

type addNumbersPayload {
  result: Int!
  clientMutationId: String
}

type Mutation {
  addNumbers(input: addNumbersInput!): addNumbersPayload!
  # ...
}

# ...