Add postgres upsert
mutations to postgraphile.
yarn add @fullstackio/postgraphile-upsert-plugin
postgraphile --append-plugins @fullstackio/postgraphile-upsert-plugin:PgMutationUpsertPlugin
See here for more information about loading plugins with PostGraphile.
const express = require("express");
const { postgraphile } = require("postgraphile");
const {
PgMutationUpsertPlugin
} = require("@fullstackio/postgraphile-upsert-plugin");
const app = express();
app.use(
postgraphile(pgConfig, schema, {
appendPlugins: [PgMutationUpsertPlugin]
})
);
app.listen(5000);
This plugin creates an addition operation to upsert<Table>
using a where
clause, which is any unique constraint on the table. Supports multi-column unique indexes.
create table bikes (
id serial PRIMARY KEY,
"serialNumber" varchar UNIQUE NOT NULL,
weight real,
make varchar,
model varchar
)
An upsert would look like this:
mutation {
upsertBike(
where: { serialNumber: "abc123" }
input: {
bike: {
serialNumber: "abc123"
weight: 25.6
make: "kona"
model: "cool-ie deluxe"
}
}
) {
clientMutationId
}
}
- This is a fork of the TypeScript postgraphile-upsert-plugin
- Which itself is a fork of the original upsert plugin