https://github.com/cdaringe/postgraphile-upsert
add postgres upsert mutations to postgraphile :elephant:
https://github.com/cdaringe/postgraphile-upsert
mutation postgraphile postgres upsert
Last synced: 11 months ago
JSON representation
add postgres upsert mutations to postgraphile :elephant:
- Host: GitHub
- URL: https://github.com/cdaringe/postgraphile-upsert
- Owner: cdaringe
- Created: 2018-11-22T21:30:52.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-08-05T22:07:07.000Z (almost 2 years ago)
- Last Synced: 2025-04-04T14:46:40.452Z (about 1 year ago)
- Topics: mutation, postgraphile, postgres, upsert
- Language: TypeScript
- Homepage:
- Size: 2.02 MB
- Stars: 31
- Watchers: 2
- Forks: 20
- Open Issues: 9
-
Metadata Files:
- Readme: readme.md
- Contributing: .github/CONTRIBUTING.md
Awesome Lists containing this project
README
# postgraphile-upsert-plugin
Add postgres `upsert` mutations to [postgraphile](https://www.graphile.org/postgraphile).
[](https://github.com/semantic-release/semantic-release)
[](https://github.com/cdaringe/postgraphile-upsert/actions/workflows/main.yml)
## Getting Started
### Install
```bash
pnpm install --save postgraphile-upsert-plugin
```
### CLI
```bash
postgraphile --append-plugins postgraphile-upsert-plugin:PgMutationUpsertPlugin
```
See [here](https://www.graphile.org/postgraphile/extending/#loading-additional-plugins) for more information about loading plugins with PostGraphile.
### Library
```ts
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` mutation. Supports multi-column unique indexes.
## Example
```sql
create table bikes (
id serial primary key,
make varchar,
model varchar
serial_number varchar unique not null,
weight real
)
```
A basic upsert would look like this:
```graphql
mutation {
upsertBike(
where: { serial_number: "abc123" }
input: {
bike: {
make: "kona"
model: "kula deluxe"
serial_number: "abc123"
weight: 25.6
}
}
) {
clientMutationId
}
}
```
## [Smart Tags](https://www.graphile.org/postgraphile/smart-tags/) Support
- Add `@omit updateOnConflict` to column comments to prevent them from being modified on _existing_ rows in an upsert mutation.
## Contributing
See [`CONTRIBUTING.md`](./.github/CONTRIBUTING.md).
## Credits
- This is a typescript-ified knock off of [the original upsert plugin](https://github.com/einarjegorov/graphile-upsert-plugin/blob/master/index.js)