GraphQL Client in Pure ReasonML. Stupid simple, magic-free client backed by plain-old fetch. Inspired by reason-apollo.
In the near future these are the planned additional features:
- integration with graphql_ppx
- Cache queries/requests
- Optimistic Updates
yarn add regql
"bs-dependencies": [
"reason-react",
"bs-fetch",
"bs-json",
"regql"
]
// Gql.re
module Client = Regql.Create({
let uri = "http://localhost:8000/graphql"
});
let query = {|
query getUser {
name
}
|};
type user = {name: string};
type data = {user: user};
let user = (json) =>
Json.Decode.{
name: json |> field("name", string),
};
let data = (json) =>
Json.Decode.{
user: json |> field("user", user)
};
module Container = {
type shape = data;
type variables; /* or some type `type variables = {"one": 1};` if used */
let decoder = data;
};
module FetchUserName = Gql.Client(Container);
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>