While following along the Craft GraphQL APIs in Elixir with Absinthe book and taking a stab at the exercises for chapter 8 (locking down the api) I came across a (for me being totally new to subscriptions in absinthe right now) strange problem that I don’t seem to find a solution for (or maybe I am struck with temporal blindness).
For reference, I created an example repository with the code that does implement the PlateSlate phoenix project as described in the book (only diverging a bit with regards to file placement and module naming).
To summarize the workings of the project: In the system there are customers and employees. Customers can place an order on some menu items. Employees can update the order and both can subscribe to updates on the orders (but customers may only receive updates for their own orders).
Within the graphiql interface this all seems to work well, but when it comes to the test cases for updating the order (update to ready and complete) it seems that the
trigger configured within the
updateOrder subscription is not executed and therefore no subscriptions data is being pushed.
What does not seem to work
There are two test cases for subscriptions on order updates, one for marking the
order as ready and one for marking it as complete.
The relevant source for the ready update test lives here
The source for the complete update test lives in the same file
In both cases, a customer and employee is created. Then two orders are created
and the customer is subscribed to the
updateOrder field for both of them.
(The way it is set up here, the subscription should succeed but delivery should
After that, for the ready order test,
Absinthe.run is used to call the
readyOrder mutation with the employee as current user. This succeeds. As can
be seen at
we publish the subscription manually using
For the complete order test,
Absinthe.run is also being used (this time to
completeOrder mutation). The main difference is here that instead
of manually publishing within the resolver, the
updateOrder field is
configured to trigger upon
:complete_order within the schema
This time it doesn’t seem to work though, the mailbox stays empty.
The project can be cloned and should be pretty ready to go I think… In order to see the failing test.
cd plate_slate mix deps.get mix test
And the tests work again when I manually trigger the subscription using
Absinthe.Subscription.publish … (uncomment the lines over here)
What would be expected
That running the mutation through absinthe run within the tests would
also cause the trigger configuration within the schema to be cause
subscription data to be delivered.
Any Ideas what the issue could be?