pillaiindu

pillaiindu

Does GraphQL with Absinthe, send and recieve data through a websocket connection or a traditional http(s)?

There is a book on using GraphQL with Absinthe (and I think they use React). There is also a course (coming) on Pragmatic Studio using the same tools.
In a SPA we load first page through a traditional HTTP(s) request and subsequent pages load through Ajax. Does the above combination use websockets for all of the subsequent requests (get, post, put, patch, delete)? If not, why not? Because the strength of Elixir is in the ability of creating and feeding so many live (websocket) connections.

Edit: Does LiveView or LiveEex use websockets by default, and is it possible to use this duo to load all of the subsequent pages through websocket connection (because LiveView already sends HTML instead of JSON).

Most Liked

kokolegorille

kokolegorille

GraphQL does not care about the network layer and can operate on http or websocket. It is a query language for your api. Usually there is one http entry point where You send queries and mutations, and socket support for subscriptions.

Loading data for your SPA does not require websocket at all… loading data for your SPA is usually done from the client, with an ajax request.

Websocket are needed when You want the server to act on the client (bidirectional) like pushing new data. But an API client does not require this because it can initiate a query when needed, usually by fetch, or axios.

That is why LiveView and the likes requires websocket to push new data on the client.

easco

easco

Forgive the pedantic nature of this response, I’m going to try and be very precise in my use of terminology.

Absinthe accepts GraphQL documents - query, mutation, and subscription documents - and helps you generate the result of those queries through an Elixir API. It is agnostic about how the document makes it to that API. For subscription documents, where results of the query can be generated asynchronously and/or over time, Absinthe requires a PubSub system and will deliver those results to that system.

The aspects of providing GraphQL documents to Absinthe over the network is handled by software that is outside of Absinthe proper. One popular choice is absinthe_plug which helps to create a Plug pipeline for submitting GraphQL documents to Absinthe. absinthe_plug supports HTTP GET and POST requests. It can also be used to set up an HTTP endpoint that delivers a GraphiQL interface.

To my knowledge absinthe_plug doesn’t do much to help you get the long running results of subscription documents. If you just want to use absinthe_plug your application will still have to provide a compatible PubSub system and find some way to deliver the results of the subscription as they are published by Absinthe.

absinthe_phoenix is a network delivery toolkit for handling GraphQL queries through Phoenix Channels. Those channels, in turn, are currently built on top of web sockets or long polling. Because Phoenix itself includes a PubSub system, absinthe_phoenix can make use of that system to deliver the asynchronous results of subscriptions through a Phoenix Channel (in addition to the synchronous results of query and mutation documents).

Where Next?

Popular in Questions Top

chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
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
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
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

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement