homanchou

homanchou

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?

Marked As Solved

maartenvanvliet

maartenvanvliet

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.11.0

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

Last Post!

austinthecoder

austinthecoder

I had a similar need. I wanted to query without the HTTP layer. Absinthe.run/3 works, but the result is map that’s meant to be turned into JSON, so things like dates are strings instead of actual date objects.

I created a custom library scratch this itch: qry | Hex

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
New