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