Craft GraphQL APIs in Elixir with Absinthe (PragProg)

Your domain is rich and interconnected, and your API should be, too. Upgrade your web API to GraphQL, using flexible queries to empower your users, and its declarative structure to simplify your code.

Bruce Williams and Ben Wilson @benwilson512

Series editor: Bruce A. Tate @redrapids
Developmental editor: Jacquelyn Carter @jkcarter

Your domain is rich and interconnected, and your API should be, too. Upgrade your web API to GraphQL, using flexible queries to empower your users, and its declarative structure to simplify your code. Master Absinthe, the GraphQL toolkit for Elixir, a functional programming language designed to enable massive concurrency atop robust application architectures.

Offer a more tailored, cohesive experience to your users, easily aggregate data from different data sources, and improve your back end’s maintainability with Absinthe’s declarative approach to defining your API. Expand your schema to suit your application’s needs. Support users flexibly but responsibly with complexity analysis and persisted queries. Use asynchronous and batching execution, or extend Absinthe with custom add-ons. Go live with subscriptions, delivering data over websockets on top of Elixir’s famous solid performance and real-time capabilities.

Transform your applications for performance and flexibility with Elixir, GraphQL, and Absinthe.


“If we’re lucky, about once per decade or so we’ll come across a technology that has the chance to revolutionize the Web. GraphQL is one such set of technologies. This book is written by two of the industry’s experts—co-authors of one of the best and most complete GraphQL implementations.”

–Chad Fowler, Microsoft and BlueYard Capital


Don’t forget you can get 35% off with your Devtalk discount! Just use the coupon code “devtalk.com" at checkout :+1:

2 Likes

I am not able to run the sample code with

Erlang/OTP 23 [erts-11.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]
Elixir 1.10.4 (compiled with Erlang/OTP 22)

Getting an error when running ecto.setup

15:11:53.219 [error] GenServer #PID<0.5306.0> terminating
** (ArgumentError) argument error
    :erlang.element(1, :error)
    (postgrex 0.13.3) lib/postgrex/utils.ex:67: anonymous fn/1 in Postgrex.Utils.parse_version/1
    (elixir 1.10.4) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2
    (elixir 1.10.4) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2
    (postgrex 0.13.3) lib/postgrex/utils.ex:67: Postgrex.Utils.parse_version/1
    (postgrex 0.13.3) lib/postgrex/protocol.ex:641: Postgrex.Protocol.bootstrap_send/6
    (postgrex 0.13.3) lib/postgrex/protocol.ex:475: Postgrex.Protocol.handshake/2
    (db_connection 1.1.2) lib/db_connection/connection.ex:134: DBConnection.Connection.connect/2
    (connection 1.0.4) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.13.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
** (Mix) The database for PlateSlate.Repo couldn't be created: an exception was raised:
    ** (ArgumentError) argument error
        :erlang.element(1, :error)
        (postgrex 0.13.3) lib/postgrex/utils.ex:67: anonymous fn/1 in Postgrex.Utils.parse_version/1
        (elixir 1.10.4) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2
        (elixir 1.10.4) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2
        (postgrex 0.13.3) lib/postgrex/utils.ex:67: Postgrex.Utils.parse_version/1
        (postgrex 0.13.3) lib/postgrex/protocol.ex:641: Postgrex.Protocol.bootstrap_send/6
        (postgrex 0.13.3) lib/postgrex/protocol.ex:475: Postgrex.Protocol.handshake/2
        (db_connection 1.1.2) lib/db_connection/connection.ex:134: DBConnection.Connection.connect/2
        (connection 1.0.4) lib/connection.ex:622: Connection.enter_connect/5
        (stdlib 3.13.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
2 Likes

The source contains 48 code examples each for different chapter. Can you please specify which one are you trying to run? I have checked first. Obviously those code examples are old, so there are lots of deprecation warnings, but the code is still working. Are you sure your database is started and you have a proper credentials in project configuration?

2 Likes

Thank you for your reply Elji, I started form the beginning so the very first code sample 02-chp.schema\1-start fails.

I am sure I have the database started and the proper credentials.

In fact the error is really similar to https://github.com/elixir-ecto/postgrex/issues/370 but when I try to update the libraries I get in all sorts of other issues.

1 Like

Ok, I see … Here is another issue which better describes problem:

I was unable to reproduce this issue as PostgreSQL in my local asdf-based setup gives such output:

$ psql --version
psql (PostgreSQL) 13.0

Then run mix deps.update postgrex and give us more information about your “other issues”, please.

1 Like

Hm, actually the update command worked this time find and I could start the server.

I previously tried mix deps.update and that lead to issues.

Thank you for your support, issue fixed. If the code samples where in a github repo I would not mind making a pr with this fix.

3 Likes

@alexandru-calinoiu Ben Wilson, one of the authors, is on this forum – you can tag him like this: @benwilson512 if you want to ask him a question.

2 Likes

Thank you,

I’ve figured it out eventually, needed to update one of the packages.

2 Likes

Hey folks,

I’ve got the paper version of the book but I’ve seen that there’s a second print edition.
Are the two versions so different? I bought it a while ago but just started reading it this week.

2 Likes

@benwilson512 Is there a Github Project for “Craft GraphQL APIs in Elixir with Absinthe” that provides a roadmap for the 2nd edition of this book?

2 Likes

Hey @conradwt there is not a 2nd edition of the book, nor is there a roadmap for one. It is probably due for one at this point, but while Absinthe itself has had a wonderful set of contributors continue to keep it up to date, the authors of the book (Bruce and myself) are not able to put the effort required into writing a second edition at this time.

3 Likes