regql
reason graphql
Last updated 3 years ago by kennetpostigo .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install regql 
SYNC missed versions from official npm registry.

Regql

version downloads MIT License

GraphQL Client in Pure ReasonML. Stupid simple, magic-free client backed by plain-old fetch.

Install

# regql peer dependencies
yarn add regql reason-react bs-fetch

# graphql_ppx for some nice compile-time validation
yarn add --dev graphql_ppx

bsconfig

"bs-dependencies": [
  "reason-react",
  "bs-fetch",
  "regql"
],
"ppx-flags": ["graphql_ppx/ppx"],

Usage

Instantiate the client and pass it configuration:

// Client.re
module Client = Regql.Create({
  let uri = "http://localhost:8000/graphql"
  let token = ""; /* leave blank if no token */
});

Query Example

/* Create a GraphQL Query by using the graphql_ppx */
module PokemonQuery = [%graphql {|
  query getPokemon($name: String!){
      pokemon(name: $name) {
          name
      }
  }
|}];

module Query = Client.Instance.Query;

let make = (_children) => {
  /* ... */
  render: (_) => {
    let pokemonQuery = PokemonQuery.make(~name="Pikachu", ());
    <Query query=pokemonQuery>
      ...((response, parse) => {
        switch response {
           | Loading => <div> (Utils.ste("Loading")) </div>
           | Failed(error) => <div> (Utils.ste(error)) </div>
           | Loaded(result) => <div> (Utils.ste(parse(result)##user##name)) </div>
        }
      })
    </Query>
  }
}

Mutation Example

module PokemonMutation = [%graphql {|
  mutation addPokemon($name: String!) {
      addPokemon(name: $name) {
          name
      }
  }
|}];

module Mutation = Client.Instance.Mutation;

let make = (_children) => {
  /* ... */
  initialState: {
    parse
  },
  reducer: (action, state) =>
    switch (action) {
    | AddParser(parse) => ReasonReact.Update({...state, parse})
  },
  render: ({reduce, state: {parse}}) => {  
    <Mutation>
      ...((
        mutate /* Mutation to call */,
        result /* Result of your mutation */
      ) => {
          let mutationResponse = switch result {
            | NotCalled => <div>  (Utils.ste("Not Called")) </div>
            | Loading => <div> (Utils.ste("Loading")) </div>
            | Loaded(response) => <div> (Utils.ste(parse(result)##addPokemon##name ++ " addded")) </div>
            | Failed(error) => <div> (Utils.ste(error)) </div>
          };
        <div>
          <button onClick=((_mouseEvent) => {
              let pokemonMutation = PokemonMutation.make(~name="Reason", ());
              mutate(pokemonMutation);
              reduce(() => AddParser(pokemonMutation##parse), ());
            })>
            (Utils.ste("Add Pokemon"))
          </button>
          <div> (mutationResponse) </div>
        </div>
      })
    </Mutation>
  }
}

Current Tags

  • 0.5.0-beta.13                                ...           beta (2 years ago)
  • 0.4.6                                ...           latest (3 years ago)

31 Versions

  • 0.5.0-beta.13                                ...           2 years ago
  • 0.5.0-beta.12                                ...           2 years ago
  • 0.5.0-beta.11                                ...           2 years ago
  • 0.5.0-beta.9                                ...           3 years ago
  • 0.5.0-beta.8                                ...           3 years ago
  • 0.5.0-beta.7                                ...           3 years ago
  • 0.5.0-beta.6                                ...           3 years ago
  • 0.5.0-beta.5                                ...           3 years ago
  • 0.5.0-beta.4                                ...           3 years ago
  • 0.5.0-beta.3                                ...           3 years ago
  • 0.5.0-beta.2                                ...           3 years ago
  • 0.5.0-beta.1                                ...           3 years ago
  • 0.4.7-beta.5                                ...           3 years ago
  • 0.4.7-beta.4                                ...           3 years ago
  • 0.4.7-beta.3                                ...           3 years ago
  • 0.4.7-beta.2                                ...           3 years ago
  • 0.4.7-beta.1                                ...           3 years ago
  • 0.4.6                                ...           3 years ago
  • 0.4.5                                ...           3 years ago
  • 0.4.4                                ...           3 years ago
  • 0.4.3                                ...           3 years ago
  • 0.4.2                                ...           3 years ago
  • 0.4.1                                ...           3 years ago
  • 0.4.0                                ...           3 years ago
  • 0.3.1                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |