package graphql_jsoo_client

  1. Overview
  2. Docs
GrpahQL over WebSocket client

Install

Dune Dependency

Authors

Maintainers

Sources

0.1.1.tar.gz
md5=f8ff512cc7adc1d0e61b2dabfa948765
sha512=a4bbf8a5b2c45206965e2a55a6fdc270eaadda1e9be0e00c9fb91d6d06295c8c17217ec6d94b6044e8a27b0b24c19581a2f96fe05e84cb681980725ed6a6c039

Description

A GraphQl client that can be compiled using jsoo to access GraphQl servers using websocket. It was created with the main purpose of using it in combination with the Dream web-framework.

Tags

graphql jsoo websockets

Published: 30 Apr 2024

README

README.md

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.

OCaml

Innovation. Community. Security.