All Projects → lessp → revery-graphql-hooks

lessp / revery-graphql-hooks

Licence: MIT License
A library for easy handling of GraphQL with hooks for Revery

Programming Languages

reason
219 projects
shell
77523 projects

Projects that are alternatives of or similar to revery-graphql-hooks

jitm
JITM is an automated tool to bypass the JIT Hooking protection on a .NET sample.
Stars: ✭ 27 (-20.59%)
Mutual labels:  hooks
hook-into-props
Tiny HoC to use React hooks with class components.
Stars: ✭ 44 (+29.41%)
Mutual labels:  hooks
React-Combine-Provider
combine react providers in ease
Stars: ✭ 29 (-14.71%)
Mutual labels:  hooks
zoov
Use 🐻 Zustand with Module-like api
Stars: ✭ 24 (-29.41%)
Mutual labels:  hooks
hulks
Olist custom linting hooks 💚 👽
Stars: ✭ 25 (-26.47%)
Mutual labels:  hooks
useReactHooks
useReactHooks is a curated list of custom react hooks that will benefit people in their daily tasks related to development in react.
Stars: ✭ 42 (+23.53%)
Mutual labels:  hooks
micro-observables
A simple Observable library that can be used for easy state management in React applications.
Stars: ✭ 78 (+129.41%)
Mutual labels:  hooks
react-native-aria
A library of React Hooks for React-Native (Android/iOS/web) to provide accessible UI primitives for a design system.
Stars: ✭ 164 (+382.35%)
Mutual labels:  hooks
zhooks
Display Zsh hook functions and arrays
Stars: ✭ 36 (+5.88%)
Mutual labels:  hooks
Ant-Design-Pro-V5
Ant Design Pro V5 详细配置,包括分模块打包,ahooks的使用,L7 地图组件的封装,合理的初始化数据,更有动态表单、动态表格、OSS图片上传等优秀组件(项目会逐渐迭代)~
Stars: ✭ 28 (-17.65%)
Mutual labels:  hooks
atomic-state
A decentralized state management library for React
Stars: ✭ 54 (+58.82%)
Mutual labels:  hooks
ph-malhide
Process Hacker 2 hiding from external applications
Stars: ✭ 17 (-50%)
Mutual labels:  hooks
gatsby-react-hooks
An example of using Gatsby with React hooks
Stars: ✭ 26 (-23.53%)
Mutual labels:  hooks
pinipig
🚀 Performant webservice framework
Stars: ✭ 25 (-26.47%)
Mutual labels:  hooks
RT7-example
Code for the React Table 7 article
Stars: ✭ 32 (-5.88%)
Mutual labels:  hooks
react-usemiddleware
React >=16.7 hook, allowing to use standard Redux middleware with useReducer
Stars: ✭ 19 (-44.12%)
Mutual labels:  hooks
ieaseMusic
网易云音乐第三方🎵
Stars: ✭ 62 (+82.35%)
Mutual labels:  hooks
Oxide.Patcher
IL patcher for use with adding Oxide support to .NET games
Stars: ✭ 27 (-20.59%)
Mutual labels:  hooks
document-title
React hook for updating the document-title
Stars: ✭ 60 (+76.47%)
Mutual labels:  hooks
use-mutation
🧬 Run side-effects safely in React
Stars: ✭ 81 (+138.24%)
Mutual labels:  hooks

Revery GraphQL Hooks

All Contributors

A library for easy handling of GraphQL within Revery using graphql_ppx.

Table of Contents

  1. Getting started
  2. Syntax
  3. Todo
  4. Contributing
  5. License

Getting started

Installing

In your package.json/esy.json add:

"dependencies": {
  ...
  "graphql_ppx": "reasonml-community/graphql_ppx:esy.json",
  "revery": "revery-ui/revery",
  "revery-graphql-hooks": "lessp/revery-graphql-hooks",
}

You will also need to copy anu resolutions in example.json except for revery-graphql-hooks.

then in your dune-file:

(preprocess
  (pps
    graphql_ppx ;; + any other preprocessors (e.g. brisk-reconciler.ppx) for Revery
  ))
(libraries
  ;; any other libraries
  Revery Revery.lwt revery-graphql-hooks)

Setup

Create a file, lets name it Graphql.re for easy access.

In this file we'll specify some settings for our HTTP-calls.

(If you'd like to try out the example below, you can use: https://hello-graphql-api.lessp.now.sh/api)

module Config = {
  let baseUrl = "https://your_graphql_api_endpoint.com/";
  let headers = [];
};

include ReveryGraphqlHooks.Make(Config);

NOTE: For Revery to handle Promises we need to start the event loop. Add the following line, prior to calling UI.start.

let _startEventLoop = Revery_Lwt.startEventLoop();

That's all, we can now make some queries!

Syntax

Query

module HelloQueryConfig = [%graphql
  {|
    query Hello {
      hello {
        name
      }
    }
  |}
];

let%component make = () => {
  let%hook status = Graphql.useQuery(HelloQueryConfig.definition, ());

  let text = switch (status) {
  | Idle => "Idle"
  | Data(query) => query#hello#name
  | Loading => "Loading..."
  | Error => "Error"
  };

  <Text text />;
};

Mutation

module AddGreetingConfig = [%graphql
  {|
    mutation AddGreeting($greeting: String!) {
      addGreeting(greeting: $greeting)
    }
  |}
];

let%component make = () => {
  let%hook (addGreetingMutation, status) =
    Graphql.useMutation(AddGreetingConfig.definition, ());

  let text =
    switch (status) {
    | Idle => "Idle"
    | Data(query) => query#addGreeting
    | Loading => "Loading..."
    | Error => "Error"
    };

  <Center>
    <Button
      onClick={_ =>
        addGreeting(
          ~variables=AddGreeting.makeVariables(~greeting="Cheers", ()),
          (),
        )
      }
      title="Click to add"
    />
    <Text text />
  </Center>;
};

ToDo

  • Propagate updates to hooks with the same queries
  • Simplify API by using definition from graphql_ppx
  • Cache

Contributing

Contributions are more than welcome! Start by cloning this repository. The runnable example is located in examples/, the library itself is located in src/.

# to build the library
esy

# to run the examples
esy '@example' start

License

This project is licensed under the MIT License - see the LICENSE file for details

Contributors

Thanks goes to these wonderful people (emoji key):


Tom Ekander

🤔 💻 📖

Margarita Krutikova

🤔

Danny Martini

🤔 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].