Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.
/ reason-urql Public archive
forked from teamwalnut/rescript-urql

Reason bindings for Formidable's Universal React Query Library, urql.

License

Notifications You must be signed in to change notification settings

jeddeloh/reason-urql

 
 

Repository files navigation

reason-urql

npm All Contributors Build Status Maintenance Status Spectrum

Reason bindings for Formidable's Universal React Query Library, urql.

✨Features

  • ⚛️ A fully featured GraphQL client for ReasonReact.
  • ✅ Compile time type and schema validation.
  • ⚙️ Customizable behavior via exchanges.
  • 🎣 Support for useQuery, useMutation, useDynamicMutation, useSubscription, and useClient hooks!
  • ⚡ Support for server-side rendering with Next.js.

reason-urql is a GraphQL client for ReasonReact, allowing you to hook up your components to queries, mutations, and subscriptions. It provides bindings to urql that allow you to use the API in Reason, with the benefits of a sound type system, blazing fast compilation, and opportunities for guided customization.

📋 Documentation

💾 Installation

1. Install reason-urql.

yarn add reason-urql

2. Add graphql_ppx_re or graphql_ppx.

To get the most out of compile time type checks for your GraphQL queries, mutations, and subscriptions, we recommend using one of the PPX rewriters available for Reason / OCaml. Currently, there are two options in the community – graphql_ppx_re, which is under active maintenance, and graphql_ppx, which is no longer actively maintained. We strongly encourage use of graphql_ppx_re, as useDynamicMutation makes direct use of some of its newer internals. If using bs-platform@6.x.x, you'll have to use graphql_ppx_re.

yarn add @baransu/graphql_ppx_re --dev

3. Update bsconfig.json.

Add reason-urql to your bs-dependencies and graphql_ppx_re or graphql_ppx (depending on which library you're using) to your ppx_flags in bsconfig.json.

{
  "bs-dependencies": ["reason-urql"],
  "ppx-flags": ["@baransu/graphql_ppx_re/ppx"]
}

If you're using bs-platform@6.x.x, you'll need to use @baransu/graphql_ppx_re/ppx6:

{
  "ppx-flags": ["@baransu/graphql_ppx_re/ppx6"]
}

4. Send an introspection query to your API.

Finally, you'll need to send an introspection query to your GraphQl API, using a tool like graphql-cli. You should generate a file called graphql_schema.json at the root of your project that your chosen PPX preprocessor can use to type check your queries. You should check this file into version control and keep it updated as your API changes.

If using grapqhl_ppx_re, follow the instructions here.

If using graphql_ppx, you'll already have a little utility to help you generate the graphql_schema.json file:

yarn send-introspection-query <your_graphql_endpoint>

Simply re-run this script at anytime to regenerate the graphql_schema.json file according to your latest backend schema. See the docs for graphql_ppx_re and the docs for grapqhl_ppx for more assistance.

Older Versions

Before version 1.0.0, reason-urql listed urql as a peer dependency. If using v0.1.1 or earlier of reason-urql, make sure to install the correct version of urql.

yarn add reason-urql@0.1.1 urql@0.2.2

💻 Example Projects

reason-urql has a nice set of examples showing how to use the basic components and APIs to get the most out of GraphQL and Reason in your app – check them out in the /examples folder. To run any of the examples, follow these simple steps.

# 1. Navigate into the example of choice.
cd examples/1-execute-query-mutation

# 2. Install dependencies.
yarn

# 3. In one terminal, compile the source in watch mode.
yarn start

# 4. In another terminal, start the demo app server.
yarn start:demo

The example will start up at http://localhost:8080. Edit the example freely to watch changes take effect.

Editing reason-urql source files

If developing on the main reason-urql source files (i.e. anything in /src/) and you want to test the changes in one of the examples, you'll need to do the following:

# Save your changes to source, then take the following steps.

# 1. Clean any artifacts from previous builds.
yarn clean

# 2. Rebuild the source.
yarn build

# 3. Clean example build and reinstall dependencies.
cd examples/2-query
yarn clean
yarn

Since we are linking the examples' dependency on reason-urql to the src directory, it's important to clean builds between changes to prevent any stale or erroneous artifacts.

Getting Involved

Please help out by opening an issue or filing a PR.

Contributors

This project follows the all contributors spec. Thanks to these wonderful folks for contributing (Emoji Key):


Parker Ziegler

💻 📖 👀 🤔

Khoa Nguyen

💻 📖

Phil Plückthun

🤔

Kara Stubbs

💻 ⚠️ 💡

Marcos Felipe Pimenta Rodrigues

📖

Gustavo Aguiar

💻 💡

Avery Morin

🤔 💻 💡 📖

Alain Armand

💻 💡

Robin Weser

📖

Cem Turan

📖

Huy Nguyen

📖

Sean Grove

💻 💡 🤔 📖

Tomasz Cichocinski

💻 🐛

Jovi De Croock

💻

Corentin Leruth

📖

Maintenance Status

Experimental: This project is quite new. We're not sure what our ongoing maintenance plan for this project will be. Bug reports, feature requests and pull requests are welcome. If you like this project, let us know!

About

Reason bindings for Formidable's Universal React Query Library, urql.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Reason 85.5%
  • C++ 14.1%
  • JavaScript 0.4%