Skip to content

hansole/graphql_jsoo_client

Repository files navigation

A library for making WebSocket connections for use with with GraphQL.

This is the client side implementation of the GraphQL over WebSocket Protocol. It is mainly intended for use with Dream, which implements the server side. This library supports writing client code in Ocaml, that will run in the browser.

Building and install

It can be installed from source

graphql_jsoo_client$ dune build
graphql_jsoo_client$ dune install

If you makes changes to the schema of the server, you need to first build and run the server.

graphql_jsoo_client$ dune build example/server
graphql_jsoo_client$ ./_build/default/example/server/server.exe

The export the scheme that will be used by the ocaml_ppx pre-processor.

graphql_jsoo_client$ npx get-graphql-schema http://127.0.0.1:8080/graphql -j > graphql_schema.json

Then you can build the frontend against the servers schema.

graphql_jsoo_client$ dune build example/frontend
graphql_jsoo_client$ dune build

It can be installed using opam

graphql_jsoo_client$ dune build graphql_jsoo_client.opam
graphql_jsoo_client$ opam install .

(I will try to add it to the opam repository at some later time)

Usage

The example directory has a server and a client that uses the library. It show how to do simple queries with GraphQL over WebSockets. In addition it has an example of subscriptions to a counter that counts until a limit.

There is also an example of a ping pong between the server and client where the server sends updates when a subscribed counter is updated. The client modifies this value and send it to the server as a mutation. In which case the server sends the modification as an update to the subscribed client, and so on.

Issues

Dream installed using the current version in opam, depends on a library that has a bug hat cases server to use 100% CPU when using WebSocket. The issue and a workaround for this can be found here.

There also seems to be a issue with Dream with WebSockets using large payloads.

And there are probably issues with the library, so feel free to report any findings.

References

The work has been inspired by Full-Stack WebDev in OCaml Intro.

About

GrpahQL over WebSocket client

Resources

License

Stars

Watchers

Forks

Packages

No packages published