14.7 Return an order
Start the hub and the worker, and place an order as ada through a checkout, as in chapter 13.
Keep its id, which { discover { orders { nodes { id } } } } gives her. Then start a return:
ADA=$(curl -s http://localhost:5080/dev/token/ada)
G=http://localhost:5080/trax/graphql
curl -s $G -H "Authorization: Bearer $ADA" -H 'Content-Type: application/json' \
-d '{"query":"mutation { machines { orderReturn { start(requestId: \"r-1\") { id state } } } }"}'{"data":{"machines":{"orderReturn":{"start":{"id":"0f6c1a9e-6a52-4a1f-8d0e-2c43b8f1e7a1","state":"Draft"}}}}}Send it before saying why:
ID=<the return's id>
send() { curl -s $G -H "Authorization: Bearer $ADA" -H 'Content-Type: application/json' -d '{
"query": "mutation($id: UUID!) { machines { orderReturn { '"$1"' { state problem { code message } } } } }",
"variables": { "id": "'$ID'" } }'; echo; }
send 'send(id: $id, requestId: \"r-2\")'{"data":{"machines":{"orderReturn":{"send":{"state":null,"problem":{"code":"GUARD_FAILED","message":"Say why you are sending it back."}}}}}}The message is the one the feature wrote. Fill it in and send it:
ORDER=<the order's id>
send 'describe(id: $id, input: { orderId: \"'$ORDER'\", reason: \"It arrived broken\" }, requestId: \"r-3\")'
send 'send(id: $id, requestId: \"r-4\")'{"data":{"machines":{"orderReturn":{"describe":{"state":"Draft","problem":null}}}}}
{"data":{"machines":{"orderReturn":{"send":{"state":"Checking","problem":null}}}}}The return is Checking, and the worker runs ReturnOrder. A moment later the view shows where
it went:
curl -s $G -H "Authorization: Bearer $ADA" -H 'Content-Type: application/json' \
-d '{"query":"{ views { returns { orderReturn { id status reason } } } }"}'{"data":{"views":{"returns":{"orderReturn":[{"id":"0f6c1a9e-6a52-4a1f-8d0e-2c43b8f1e7a1","status":"Accepted","reason":"It arrived broken"}]}}}}Start a second return as grace and give it Ada's order: it ends Refused, since the order is not
hers. Ada's view never lists Grace's return, and Grace's never lists Ada's.
SDK Reference
Write machines as features | Feature files | Feature machines | Feature bindings | AddStateMachines | Views root | trax CLI
Next: 14.8 The board