Andreas Garnæs

Type-Safe GraphQL with OCaml (part 1)

In July 2016, I spent some time writing a GraphQL endpoint for an existing application in Go. I chose to implement the endpoint in Go based on prior experience, good concurrency support and the desire to have static type system. The GraphQL library for Go, graphql-go, worked pretty well, and I was able to build the desired functionality. Still, I was left frustrated by the lack of type safety offered in Go. Everywhere the library neccessitated the use of interface{} types, and the application was littered with type casts. Code like the following was the rule rather than the exception:

Envelope Encryption with Amazon KMS

Amazon Key Management Service is a service for creating and controlling encryption keys in a safe manner, using Hardware Security Modules under the hood. KMS also offers hassle-free yearly key rotation, and logs all key usage to CloudTrail by default.

Efficient Use of Core Reader and Writer

In a previous blog post, I used Core, Async and bitstring to write a tiny library for talking to Memcached using the binary protocol. Reader and Writer are the primary I/O abstractions used in Core and also underlies my implementation. To better understand the mechanics of Reader and Writer and how to use them efficiently, I decided to examine the implementations and APIs more closely. The following is a summary of my findings.

How to test Async OCaml code

In the previous blog post, we used Core and Async to write a tiny library for talking to Memcached using the binary protocol. I wanted to write tests for the library in a readable and succint manner to ensure correctness – the type system cannot ensure binary data is parsed correctly after all. The regular go-to tool for testing OCaml code is OUnit, but this doesn’t work well with Async. As I couldn’t find a suitable library, I decided to write something myself.

Improved OCaml Memcached client with Core and Async

In the previous blog post, we implemented a simple OCaml library for talking to Memcached with the binary protocol using bitstring. The code uses the baked-in standard library and synchronous IO (blocking), so a lot of time will be wasted waiting for IO. The standard library replacement Core offers cooperative threading with callbacks through Async, similar to Javascript, EventMachine for Ruby or many others. In this blog post we’ll try to rewrite the code from the previous post to use asynchronous IO with Async.