How to execute a graphQL query without http layer?

I’ve seen it mentioned that graphQL is transport agnostic, but all the examples I’ve seen in the docs for Absinthe involve wiring Absinthe into the router.

I’ve seen test examples where one can supply a string that is the graphQL query, but it still tests going through the ConnCase and http layer.

Are there any examples of taking a string that is the graphQL POST body and triggering the schema’s resolvers directly?

The Absinthe.run/3 does what you want. You pass it a string, the schema you want to run it against and some options like variables/context.

There’s an example in the docs Absinthe — absinthe v1.7.0

  """
  query GetItemById($id: ID) {
    item(id: $id) {
      name
    }
  }
  """
  |> Absinthe.run(App.Schema, variables: %{"id" => params[:item_id]})
6 Likes