Phoenix GraphQL Tutorial with Absinthe

For those interested on using Absinthe with Apollo client via Phoenix channels, I just released a custom Apollo networkInterface just for that: apollo-phoenix-websocket

7 Likes

@ryanswapp
Why would you recommend someone to use GraphQl,
I have never used it but am wondering how could I create a login system with it etc

Ps: am a currently learning Elixir

I apologize for not seeing this sooner. Somehow it got past me! Pretty late but here are a few reasons why I like GraphQL.

  1. One HTTP Request - GraphQL makes only one HTTP request. Using another pattern like REST you would generally have to make a number of HTTP requests to get data from different resources. With GraphQL, you send one query to the server and it sends back all the data you need without having to make multiple requests.

  2. Type Checking - In GraphQL you define the fields and types that can be queried or that can be input into a mutation. As a result, you get data validation out of the box. You don’t have to do any type checking on mutation arguments because GraphQL already does it for you.

  3. Querying Nested Data - Let’s say you have an app that lawyers use to manage their cases. Each lawyer can have many cases. The case has a foreign key property called lawyer_id. With GraphQL, I can set up a lawyer field that takes the lawyer_id on a case and requests the lawyer’s data. So, I could query for a case like this:

{
  case {
    lawyer {
      first_name,
      last_name
    }
}

This comes in really handy with complex schemas.

There are a quite a few more benefits but I think the best way to identify them is to build something. Let me know if you have any questions.

4 Likes