Absinthe IF inside the field resolution?

Hi, I need to have an IF inside the field resolution (Because some services are only availabe in production envirorment).

What would be the recommended way to proceed?

    field :user, list_of(:user) do
       resolve fn member, _, _ ->
         batch({Accounts, :get_users_by_id}, member.user_id, fn batch_results ->
           {:ok, Map.get(batch_results, member.user_id)}

Resolution is just a normal function - you can actually define the function in a separate module (not schema) and use it with:

resolve &MyModule.my_fun/3

The function receives 3 arguments:

  • parent graph element, arguments and Absinthe.Resolution structure.

For a reusable mechanism to block some methods in some case use an Absinthe middleware (not Plug middleware)

Thanks @marcin.

I got confused for a moment!

By the way, if you’re not doing it already Absinthe’s “context” might be a good place to put a value indicating which environment you’re in if many different resolvers will need it. Easy to pattern match on in resolver function definitions too: The Context and Authentication — absinthe v1.6.2