sltx-nexus-plugin-relay-mutation
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

@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!
  # ...
}

# ...

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i sltx-nexus-plugin-relay-mutation

      Weekly Downloads

      1

      Version

      0.3.1

      License

      MIT

      Unpacked Size

      33.4 kB

      Total Files

      11

      Last publish

      Collaborators

      • passionkind