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

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

# ...

Package Sidebar

Install

npm i @jcm/nexus-plugin-relay-mutation

Weekly Downloads

61

Version

0.2.0

License

MIT

Unpacked Size

31.7 kB

Total Files

11

Last publish

Collaborators

  • jonathancardoso