I’ve created a set of macros to help reduce a bunch of boilerplate when dealing with CQRS applications but am stuck on one detail.
I’m not sure how to validate that a module macro argument is what I need it to be.
Example on line 40
If CreateUser
is not Module with a __command__
function – say I typo-ed it as CreateUse
– I’d love to simply bail out of compilation right away with the details on why it’s invalid.
But the exception gets lost in compilation and just fails at the level of Absinthe compilation.
This works correctly when the macro is top-level as you can see here on line 7
But in the first example I receive
== Compilation error in file lib/example_api/schema.ex ==
** (Absinthe.Schema.Error) Compilation failed:
---------------------------------------
## Locations
Could not load module `Elixir.ExampleApi.Types.UserTypes`. It returned reason: `unavailable`.
I’m guessing that it’s because I’m already in the context of an Absinthe macro by calling Module.eval_quoted(__CALLER__, quoted)
. But I’m at the limit of my knowledge here.
Relevant code here
Second question is how I can defer checking these modules until the last possible moment?
As of now, I’m forced to call module.__info__/1
in Guards and it feels dirty.
I hope this makes sense. If not, I’m open to discussion.