TIL - Implementing Encoder for NifStructs

I am currently using Rustler, a tool that allows for Elixir to interact with the Rust ecosystem. As a newcomer to Rust, working on Rust-Elixir crossover libraries helps me understand its quirks. Today, I was trying to use a SQL parser in Rust and convert the results to Elixir terms. Rustler’s NifStructs feature made this process convenient. However, I encountered an issue with a data structure defined as follows: #[derive(NifStruct)] #[module = "SqlParser. »

Creating an Input Union Type System Directive in Absinthe

In this post I will explain how to create a type system directive in Absinthe to implement Input Unions in Graphql. The code for this post can be found on Github A common issue with GraphQL is the lack of input unions. This means an input object that lets you choose between a number of potential input types. For example (taken from a spec discussion): input PetInput { cat: CatInput dog: DogInput fish: FishInput } input CatInput { name: String! »

Formatting GraphQL in Elixir projects

With the release of Elixir 1.13 it became possible to add plugins to the formatter. These plugins gives developers the option to hook into the Elixir formatter. I’ve created an Elixir formatter plugin to Absinthe to format GraphQL documents. With the release of Absinthe 1.7 this is available for everyone to use. To start, you’ll need Absinthe 1.7 or higher together with Elixir 1.13 or higher. The Absinthe project comes with Absinthe. »

Absinthe subscriptions with ReasonML and Urql

Lately I’ve been looking into ReasonML as a language to pick up. In the past I’ve dabbled with Elm and really enjoyed it but it’s lack of interoperability with javascript hampers its development. ReasonML offers a far better story in this regards, there are excellent React and React-Native libraries/bindings available as well as bindings for popular Graphql clients. That, combinated with great type-safety makes it a compelling alternative to Elm and Typescript. »

Urql graphql subscriptions with Absinthe

Many Graphql stacks use Apollo as the javascript client library. It’s well maintained, popular and has lot’s of examples. It also works together with Absinthe, the Elixir Graphql library. If you need to use graphql subscriptions in combination with Apollo and Absinthe there is the socket-apollo-link to connect the two. There’s another interesting javascript client library for Graphql on the horizon, Urql. It’s a bit more lightweight and looks really promising. »

Using Recursive Common Table Expressions with Ecto

A presentation I gave at the Amsterdam Elixir Meetup. We faced a problem where we needed to recursively load records from a database. The application was doing the recursion itself, recursively querying the mariadb instance. I explained how we moved to RCTE’s and how this works in Ecto. Slides »

Writing your own Absinthe DSL with macros and middleware

Absinthe is a great library to do graphql in Elixir. However, when writing your resolvers you may find that you are writing some boilerplate multiple times. So, in the spirit of keeping your code DRY, in this post I’ll show how we can leverage middleware and a macro to write your own DSL for your Graphql api. I assume some basic knowledge on how Absinthe works, most of the information can be found on in the guides »