Open maennchen opened 6 years ago
Right, this is a good question.
Here's the issue generally: Right now middleware doesn't work with subscription config
at all. The reason is simple: Middleware runs during the resolution phase, but subscription documents don't run resolution on setup, they run resolution on publication.
Your specific error message is a slightly different problem, this happens because you've added middleware to the field but haven't added a resolver. If middleware is added to a field via the middleware
macro, then no default resolver is applied. ParseIDs
doesn't resolve the field (not its job to) so when the doc is published you get an error.
Honestly I'm not entirely sure what the best approach here is. Perhaps the best option is to create a middleware like mechanic that operates directly on the AST for stuff like argument transformation, and move ParseIDs to using that.
I just ran into this issue as well. It's easy enough to parse the global ID in the config function (or convert to a global ID in the trigger I guess), but it took me a few minutes to understand that the middleware wasn't working like I assumed it would. Perhaps adding a note in the moduledoc for ParseID
would be worthwhile?
@jcelliott PR welcome for that note!
When trying to use the
Absinthe.Relay.Node.ParseIDs
middleware for arguments in subscriptions, the following error is thrown.If you're interested I could build a PR to solve the issue.