Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kennetpostigo/regql
Reason Graphql
https://github.com/kennetpostigo/regql
client graphql reason
Last synced: 2 months ago
JSON representation
Reason Graphql
- Host: GitHub
- URL: https://github.com/kennetpostigo/regql
- Owner: kennetpostigo
- License: mit
- Created: 2017-11-22T04:06:00.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-31T04:24:08.000Z (over 6 years ago)
- Last Synced: 2024-09-08T01:59:23.192Z (4 months ago)
- Topics: client, graphql, reason
- Language: JavaScript
- Homepage:
- Size: 41 KB
- Stars: 19
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# Regql
[![version](https://img.shields.io/npm/v/regql.svg?style=flat-square)](http://npm.im/regql)
[![downloads](https://img.shields.io/npm/dm/regql.svg?style=flat-square)](http://npm-stat.com/charts.html?package=regql)
[![MIT License](https://img.shields.io/npm/l/regql.svg?style=flat-square)](http://opensource.org/licenses/MIT)GraphQL Client in Pure [ReasonML](https://reasonml.github.io). Stupid simple,
magic-free client backed by plain-old fetch. Inspired by
[reason-apollo](https://github.com/Gregoirevda/reason-apollo).## RoadMap
In the near future these are the planned additional features:
* [ ] integration with [graphql_ppx](https://github.com/mhallin/graphql_ppx)
* [ ] Cache queries/requests
* [ ] Optimistic Updates## Install
```bash
yarn add regql
```## bsconfig
```json
"bs-dependencies": [
"reason-react",
"bs-fetch",
"bs-json",
"regql"
]
```## Usage
#### Instantiate the client and pass it configuration:
```reason
// Gql.re
module Client = Regql.Create({
let uri = "http://localhost:8000/graphql"
});
```#### Create a query
```reason
let query = {|
query getUser {
name
}
|};
```#### Define the response shape
```reason
type user = {name: string};
type data = {user: user};
```#### Define Decoder for your response
```reason
let user = (json) =>
Json.Decode.{
name: json |> field("name", string),
};let data = (json) =>
Json.Decode.{
user: json |> field("user", user)
};
```#### Define Container configuration
```reason
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
```reason
module FetchUserName = Gql.Client(Container);
```### Use the FetchUserName Component
```reason
render: (_) =>((response) => {
switch response {
| Loading =>(ReasonReact.stringToElement("Loading"))
| Failed(error) =>(ReasonReact.stringToElement(error))
| Loaded(result) =>(ReasonReact.stringToElement(result.user.name))
})```