graphile-upsert-plugin

1.0.0 • Public • Published

graphile-upsert-plugin

This postgraphile plugin adds root level mutations for upserting with an equivalent API to the standard Create/Update mutations (upsert${Table}) using postgres INSERT INTO ON CONFLICT UPDATE statements. It includes:

  • A single record mutation index.js (original) --append-plugins graphile-upsert-plugin
  • batch.js, which accepts a non-empty list of records --append-plugins graphile-upsert-plugin/batch
  • batch-allow-empty.js which is the same but with empty values allowed --append-plugins graphile-upsert-plugin/batch-allow-empty The last two are the exact same, eventually the difference will just be a configuration but for now they're copy-pasted

If you add both via --append-plugins graphile-upsert-plugin,graphile-upsert-plugin/batch, your schema should look something like:

"""All input for the upsert `Event` batch mutation."""
# ...

input UpsertEventBatchInput {
  clientMutationId: String

  """
  The `Events` to be upserted by this mutation. Expects all records to conform to the structure of the first.
  """
  events: [EventInput!]!
}

# ...

type Mutation {
  # ...

  """Upserts a single `Event`."""
  upsertEvent(
    """
    The exclusive input argument for this mutation. An object type, make sure to see documentation for this object’s fields.
    """
    input: UpsertEventInput!
  ): UpsertEventPayload

  """Upserts a batch of `Events`."""
  upsertEventBatch(
    """
    The exclusive input argument for this mutation. An object type, make sure to see documentation for this object’s fields.
    """
    input: UpsertEventBatchInput!
  ): UpsertEventBatchPayload

  # ...
}

# ...

Readme

Keywords

none

Package Sidebar

Install

npm i graphile-upsert-plugin

Weekly Downloads

538

Version

1.0.0

License

MIT

Unpacked Size

39.5 kB

Total Files

6

Last publish

Collaborators

  • micimize