# GraphQL queries?

**URL:** <https://discuss.ocaml.org/t/graphql-queries/13060>\
**Category:** Ecosystem\
**Created:** [September 20, 2023, 3:11pm UTC](https://discuss.ocaml.org/t/graphql-queries/13060 "2023-09-20T15:11:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarkoSchuetz](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/markoschuetz/32/3370_2.png) [@MarkoSchuetz](https://discuss.ocaml.org/u/MarkoSchuetz)\
**Post date:** [September 20, 2023, 3:11pm UTC](https://discuss.ocaml.org/t/graphql-queries/13060/1 "2023-09-20T15:11:54Z")

</div>

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](https://github.com/andreas/ocaml-graphql-server)** would that be the recommended starting point for a GitHub App?

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [September 20, 2023, 6:40pm UTC](https://discuss.ocaml.org/t/graphql-queries/13060/2 "2023-09-20T18:40:10Z")

</div>

If you want to set up a GraphQL _server_ then you might as well use [Dream](https://ocaml.org/p/dream/latest) 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](https://graphql-ppx.com/docs/installation-on-native) 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 🙂

---

<div class="post-metadata">

**Author:** ![MarkoSchuetz](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/markoschuetz/32/3370_2.png) [@MarkoSchuetz](https://discuss.ocaml.org/u/MarkoSchuetz)\
**Post date:** [September 21, 2023, 5:02pm UTC](https://discuss.ocaml.org/t/graphql-queries/13060/3 "2023-09-21T17:02:25Z")

</div>

Thank you for the answer!

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

```auto
let v =
  [%graphql
      {|
       query {
         viewer {
           login
         }
       }
|}];;

```

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…

---

<div class="post-metadata">

**Author:** ![amongonz](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@amongonz](https://discuss.ocaml.org/u/amongonz)\
**Post date:** [September 22, 2023, 1:53am UTC](https://discuss.ocaml.org/t/graphql-queries/13060/4 "2023-09-22T01:53:04Z")

</div>

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](https://github.com/teamwalnut/graphql-ppx/blob/1345e061a92394b651b5ac65a035fda4190292e4/src/ppx/graphql_ppx.ml#L1094-L1099), as in `(preprocess (pps graphql_ppx -native))`. How lame this isn’t documented.
