Skip to content
master
Switch branches/tags
Code
This branch is 11 commits ahead, 117 commits behind cdaringe:master.

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
Nov 22, 2018
Nov 22, 2018
Jan 25, 2019
Nov 22, 2018
Jan 25, 2019
Jan 25, 2019
Nov 22, 2018

postgraphile-upsert-plugin

Add postgres upsert mutations to postgraphile.

JavaScript Style Guide semantic-release Greenkeeper badge CircleCI

Getting Started

Install

yarn add @fullstackio/postgraphile-upsert-plugin

CLI

postgraphile --append-plugins @fullstackio/postgraphile-upsert-plugin:PgMutationUpsertPlugin

See here for more information about loading plugins with PostGraphile.

Library

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);

Usage

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.

Example

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
  }
}

Credits

About

No description, website, or topics provided.

Resources

Packages

No packages published