GraphQL Mutations (Write)

Create, update and delete records via GraphQL

6 min read
Print this section

From the Business tier, the GraphQL endpoint supports 10 write mutations: create, update and delete on Work Orders, Assets and Parts, plus adjustStock for inventory movements. Mutations go through the same services the application itself uses, so audit logs, notifications and reference auto-generation (WO-XX, ASS-XX, PART-XX) all behave identically.

Available mutations

  • createWorkOrder(input) โ†’ WorkOrder
  • updateWorkOrder(id, input) โ†’ WorkOrder
  • deleteWorkOrder(id) โ†’ DeleteResult
  • createAsset(input) โ†’ Asset
  • updateAsset(id, input) โ†’ Asset
  • deleteAsset(id, force?) โ†’ DeleteResult
  • createPart(input) โ†’ Part
  • updatePart(id, input) โ†’ Part
  • deletePart(id, force?) โ†’ DeleteResult
  • adjustStock(id, quantity, reason?, vendorId?, documentNumber?) โ†’ Part

Input shape

Each mutation has an InputType with safe fields only โ€” companyId, sequenceNumber, reference and createdById are filled server-side. You only pass title, description, status, priority, assetId, locationId, etc. Part inputs also accept barcode, maxStockLevel, locationId and vendorId, and quantity/minQuantity/maxStockLevel take decimals (e.g. 0.5). Enumerated fields are checked: priority must be one of LOW, MEDIUM, HIGH, CRITICAL; a work order's status one of OPEN, SCHEDULED, IN_PROGRESS, ON_HOLD, COMPLETED, VALIDATED, CANCELLED, CLOSED; an asset's status one of OPERATIONAL, DEGRADED, DOWN, MAINTENANCE, STANDBY, RETIRED. Anything else is refused with BAD_REQUEST. Part inputs also accept customReference โ€” your own code for the part (its ERP code, for instance), which part(barcode:) then matches. It is not enforced unique: that is yours to guarantee.

Example: create a work order

Create a work order: mutation($i: WorkOrderCreateInput!) { createWorkOrder(input: $i) { id title reference status createdAt } } with the variables {"i": {"title": "Pump #3 leak", "priority": "HIGH"}}

Adjusting stock

To change a part's quantity, use adjustStock with a signed delta โ€” negative to consume, positive to receive. It updates the quantity and writes a StockMovement audit row in one atomic transaction, and never lets stock fall below zero. Prefer it over updatePart(quantity), which sets an absolute value and records no stock history. You can also record where the goods came from: vendorId and documentNumber (the supplier's invoice or delivery-note number, 64 characters max) are stored on the movement itself, so the history shows who supplied them and under which document. Both are optional โ€” an ordinary consumption sends neither. The supplier must belong to your company.

Attribution

Public API requests don't have a logged-in user, so mutations are attributed to the first ADMIN of the company (or any active user as fallback). Audit logs always show a real human, never NULL.

Common errors

  • GRAPHQL_VALIDATION_FAILED โ€” the input shape does not match (for example a required title is missing)
  • BAD_REQUEST โ€” value validation failed (for example a title over 500 characters)
  • FORBIDDEN โ€” your plan is below Business
  • NOT_FOUND โ€” the id does not exist, or belongs to another company
  • FORBIDDEN โ€” the key's access level is too low (for example a READ key calling a mutation)

Tip

If you get a DateTime serialization error, check your client's DateTime scalar โ€” FreeMaint emits ISO 8601 strings.

Was this page helpful?