GraphQL queries?

I’m looking to access and consume data from the GitHub GraphQL API. I found a few repositories on GitHub most using ReScript where I would prefer OCaml. Also, there’s ocaml-graphql-server would that be the recommended starting point for a GitHub App?

If you want to set up a GraphQL server then you might as well use Dream which gives you the convenience of a full-fledged web framework and wraps ocaml-graphql-server for you.

If you want to set up a GraphQL client then the main concern is creating type-safe queries from the schema, you could try graphql-ppx which seems to be more or less maintained. However their documentation leaves a lot to be desired and you will probably need to do some digging to figure out how to make it work.

Of course GraphQL at the end of the day is usually just an HTTP server communicating in terms of JSON objects. You could choose to just implement the requests and encoding/decoding the GraphQL data JSON yourself. It’s manual but using boring tried-and-tested methods :slight_smile:

Thank you for the answer!

So, I decided to use graphql-ppx. But I have some teething issues. When I write

let v =
       query {
         viewer {

I get an error “Unbound module Js”. I added open Js_of_ocaml, but then I get error “Unbound module Js.Json”… I’d need some more hand-holding…

I’ve never used graphql-ppx, but Js.Json is part of ReScript’s (and Melange’s) standard library, used for JS interop. Sounds like graphql-ppx is generating you code for ReScript instead of native targets. You should try passing -native as a ppx argument in dune, as in (preprocess (pps graphql_ppx -native)). How lame this isn’t documented.