postgraphile-upsert-plugin

add postgres upsert mutations to postgraphile

Usage no npm install needed!

<script type="module">
  import postgraphileUpsertPlugin from 'https://cdn.skypack.dev/postgraphile-upsert-plugin';
</script>

README

postgraphile-upsert-plugin

Add postgres upsert mutations to postgraphile.

semantic-release CircleCI

Getting Started

Install

yarn add postgraphile-upsert-plugin

CLI

postgraphile --append-plugins postgraphile-upsert-plugin:PgMutationUpsertPlugin

See here for more information about loading plugins with PostGraphile.

Library

import express from "express";
import { postgraphile } from "postgraphile";
import PgMutationUpsertPlugin from "postgraphile-upsert-plugin";

const app = express();

app.use(
  postgraphile(pgConfig, schema, {
    appendPlugins: [PgMutationUpsertPlugin],
  })
);

app.listen(5000);

Usage

This plugin supports an optional where clause in your upsert<Table> mutation. Supports multi-column unique indexes.

Example

create table bikes (
  id serial primary key,
  make varchar,
  model varchar
  serial_number varchar unique not null,
  weight real,
)

An upsert would look like this:

mutation {
  upsertBike(
    where: { serial_number: "abc123" }
    input: {
      bike: {
        make: "kona"
        model: "cool-ie deluxe"
        serial_number: "abc123"
        weight: 25.6
      }
    }
  ) {
    clientMutationId
  }
}

Credits