Code Monkey home page Code Monkey logo

graphql_jsoo_client's Introduction

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.

graphql_jsoo_client's People

Contributors

hansole avatar

Stargazers

Paolo Donadeo avatar Seb Mondet avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.