[ANN] graphql 0.1.0

I’m happy to announce graphql, graphql-lwt and graphql-async are now available on OPAM!

These packages allow you to build GraphQL schemas in OCaml and execute queries against them. The current feature set includes:

  • Type-safe schema design
  • GraphQL parser in pure OCaml using angstrom (April 2016 RFC draft)
  • Query execution
  • Introspection of schemas
  • Arguments for fields
  • Allows variables in queries
  • Lwt support with graphql-lwt
  • Async support with graphql-async

This is really awesome! Do you think that a GraphQL client is very difficult from this base? I am most interested in porting the OCaml GitHub bindings to their new GraphQL API.

I think a GraphQL client will prove to be a different challenge than the server library. The query type definitions could be shared, but I don’t think that will be the hard part. I imagine you would want some kind of code generation for a GraphQL client based on the GraphQL schema (similar to how you do code generation with atdgen right now, but without having to specify all the types yourself). It would be very simple to get a barebones client without code generation up and running, but I don’t think you would get much benefit over your current setup.

On top of my head, this is the approach I would suggest in a GraphQL client library:

  1. Convert a GraphQL introspection result (JSON) into domain specific type definitions (GraphQL objects, fields, scalars, etc).
  2. Generate OCaml code for queries based on types from step 1. This should allow you to construct queries in a type-safe manner that agree with the types of the GraphQL schema.
  3. Generate OCaml code for result parsing based on the types from step 1. This should allow you to parse a GraphQL query result (JSON) into nicer OCaml types.
  4. Keep a mapping from query types to result types in the client.

Maybe step 2 and 3 could be PPX-based rather than generate code. I would be happy to help, but I’m a bit wary about spreading myself thin :slight_smile:

1 Like

More on a GraphQL client here: https://github.com/andreas/ocaml-graphql-server/issues/36#issuecomment-304995615

I’ve built a first draft of the PPX now: https://github.com/andreas/ocaml-graphql-server/pull/56


For anyone who is interested in GraphQL in OCaml, @andreas will kindly offer a tutorial at CUFP this year at Oxford. Details at http://cufp.org/2017/c8-andreas-graphql-servers-in-ocaml.html