I’m happy to announce
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
- Async support with
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:
- Convert a GraphQL introspection result (JSON) into domain specific type definitions (GraphQL objects, fields, scalars, etc).
- 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.
- 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.
- 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
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