Regql
GraphQL Client in Pure ReasonML. Stupid simple, magic-free client backed by plain-old fetch. Inspired by reason-apollo.
RoadMap
In the near future these are the planned additional features:
- integration with graphql_ppx
- Cache queries/requests
- Optimistic Updates
Install
yarn add regql
bsconfig
"bs-dependencies":
Usage
Instantiate the client and pass it configuration:
// Gql.remodule Client = Regql.Create({ let uri = "http://localhost:8000/graphql"});
Create a query
let query = {| query getUser { name } |};
Define the response shape
type user = {name: string};type data = {user: user};
Define Decoder for your response
let user = (json) => Json.Decode.{ name: json |> field("name", string), }; let data = (json) => Json.Decode.{ user: json |> field("user", user) };
Define Container configuration
module Container = { type shape = data; type variables; /* or some type `type variables = {"one": 1};` if used */ let decoder = data;};
Pass Container configuration to Gql.Client
module FetchUserName = Gql.Client(Container);
Use the FetchUserName Component
render: (_) =><FetchUserName query> ((response) => { switch response { | Loading => <div> (ReasonReact.stringToElement("Loading")) </div> | Failed(error) => <div> (ReasonReact.stringToElement(error)) </div> | Loaded(result) =><div> (ReasonReact.stringToElement(result.user.name)) </div> })</FetchUserName>