Can you get a connection instance in Absinthe.Middleware and what's the guidance on code readability and maintenance?

Hello everyone. Am currently learning Graphql and I have some few questions regarding Absinthe.

  1. Is it possible to get connection instance in the Absinthe.Middleware so that I can use Guardian.Plug.current_resource(conn) and avoid writing a separate plug to add the current user to context.
  2. How can I break my schema for better code readability and Maintainance? (I have not found a good example)

Here is my project so far.

Thank you.

Just write the extra plug. There’s no way to inject something like the conn into Absinthe without a context plug anyway, and if you’re writing that plug you’re better off pushing in the current user. Absinthe works in all kinds of medium that aren’t HTTP specific so you don’t want to rely on the plug connection.

As for breaking up your schema, see https://hexdocs.pm/absinthe/Absinthe.Schema.Notation.html#import_fields/2

4 Likes

@benwilson512
Thank you for the answer, will look at it tomorrow it pretty late here in Kenya. If I get stuck I will post the question here. :smile: