Skip to content
Pyck docs

You are reading the Dev docs (main @ e991a08). They can differ from the released product.Dev docs, not the release

Switch to LatestLatest

What a mutation starts

Audience Developer

A mutation commits its change and returns. The events it produced reach the workflows after that, in the background, so the response does not say which workflows started. Instead, the response of most mutations carries two fields that let you find out:

  • transactionID names the transaction of the mutation.
  • eventCount is the number of events the mutation published.

With these you can ask the workflow service what became of each event, and which workflow executions it started.

Both fields are non-null and sit next to the changed record in the payload of the mutation, for example in InventoryItemOutput:

type InventoryItemOutput {
inventoryItem: InventoryItem
transactionID: ID!
eventCount: Int!
}

Most mutations of the inventory, picking and receiving services return them. In the management service, so do the mutations for locations, devices and device locations, checkInUserDevice, checkOutUserDevice and sendCustomEvent. Some mutations return the record itself and have neither field, for example createCustomer. The API reference lists the return type of each mutation.

  • It identifies the database transaction the mutation ran in, and is stamped on every event the mutation published.
  • When the server retries a transaction after a conflict, each attempt gets a new ID, and the response carries the ID of the attempt that committed.
  • A retry that carries the same Idempotency-Key returns the stored response, and with it the same transactionID. See HTTP headers.
  • Workflows started from the events carry the ID in the pyck_transaction_id search attribute.
  • It is the number of events the transaction has published when the field is resolved. The server fills it after the mutation resolver has written its events and before the transaction commits.
  • It is 0 when the mutation published no event, for example because the request carries the suppressevents feature, see HTTP headers.
  • All root fields of one operation share one transaction and one counter. Each field reports the running total at the point where it resolves, so the last field of the operation holds the total.

Two queries of the workflow service answer the follow-up questions.

transactionRouting(transactionID: ID!) returns what the router has done so far for the events of one transaction. It only returns events of your tenants.

TransactionRouting has transactionID and entries, one entry per event the router has settled, oldest first. Each entry has these fields:

Field Meaning
eventID The ID of the event.
tenantID The tenant of the event.
outcome DONE when the router finished with the event: every target was delivered or refused for good. GAVE_UP when it stopped retrying after the last delivery, and the FAILED targets say what is left undone.
sequence The position of the event in the event stream.
targets What the router did for the event, a list of targets. It is empty when nothing was subscribed to the event: the event is finished with nothing to do.
recordedAt When the router recorded the entry.

Each target has a kind, and the fields that belong to it:

kind Meaning
STARTED A workflow was started, or the start returned the run an earlier delivery of the event started. Has workflow, workflowID and runID.
ALREADY_RUNNING The start was refused because the workflow ID is taken by another event’s run.
SIGNALLED A running execution was signalled. Has signal.
DROPPED Nothing was delivered, for the reason given.
FAILED The delivery failed with the error given.

Compare the number of entries with the eventCount of the mutation:

eventCount entries Meaning
0 any Nothing was published, so there is nothing to route.
n fewer than n Routing is not complete. Ask again.
n n Routing is complete. Each entry says what happened.

The status is best effort. A status write can fail and events can be skipped, so an entry can be missing for good. Ask again with a deadline instead of waiting until entries equals eventCount. Entries are kept for 72 hours.

When routing is complete, workflowExecutions(where: {transactionID: ...}) lists the executions the transaction started. The filter matches the exact ID. An empty result means that the workflows have not started or are not visible yet, or that the mutation triggered none.

Create an item and keep the handle:

mutation CreateItem($input: CreateInventoryItemInput!) {
createInventoryItem(input: $input) {
transactionID
eventCount
inventoryItem {
id
sku
}
}
}

Ask for the routing of that transaction, with the transactionID from the response:

query Routing($transactionID: ID!) {
transactionRouting(transactionID: $transactionID) {
entries {
eventID
outcome
targets {
kind
workflow
workflowID
runID
reason
error
}
}
}
}

When the number of entries equals eventCount, list the executions:

query Started($transactionID: ID!) {
workflowExecutions(where: { transactionID: $transactionID }) {
edges {
node {
execution {
workflowId
id
}
type {
name
}
status
}
}
}
}