[](https://www.npmjs.com/package/reason-urql) [](#contributors) [


[![Maintenance Status][maintenance-image]](#maintenance-status)
Reason bindings for Formidable's Universal React Query Library, urql.
- ⚛️ A fully featured GraphQL client for ReasonReact.
- ✅ Compile time type and schema validation.
- ⚙️ Customizable behavior via exchanges.
- 🎣 Support for useQuery, useMutation, 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 ReasonReact 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.
- Getting Started
- Client and Provider
- Hooks
- Exchanges
- Errors
- Advanced
``sh`
yarn add reason-urql urql graphql
yarn add gentype --dev
We try to keep our bindings as close to latest urql as possible. However, urql tends to make releases a bit ahead of reason-urql. To get a compatible version, we recommend always staying strictly within this project's peerDependency range for urql.
The gentype devDependency is a requirement introduced by urql's use of wonka. wonka's source uses @genType declarations, so when the BuckleScript / ReScript compiler attempts to compile wonka in your project, it'll need a local copy of gentype to use.
#### 1a. Important note for users of bs-platform>=8.0.0.
If using bs-platform>=8.0.0 you'll need to use yarn resolutions to specify a specific version of wonka to resolve. urql has an explicit dependency on latest wonka v4, which is incompatible with bs-platform>=8.0.0. See this issue for more details.
In your package.json, add the following:
`json`
"resolutions": {
"wonka": "5.0.0-rc.1"
}
If you're using npm, you may need to stay on bs-platform@7.3.2 until urql takes a dependency on wonka>=5.0.0.
To get the most out of compile time type checks for your GraphQL queries, mutations, and subscriptions, we use @reasonml-community/graphql-ppx. Add this to your project's devDependencies.
`sh`
yarn add @reasonml-community/graphql-ppx --dev
Add reason-urql, wonka, and @reasonml-community/graphql-ppx to your bs-dependencies and @reasonml-community/graphql-ppx/ppx to your ppx_flags in bsconfig.json.
`json`
{
"bs-dependencies": [
"reason-urql",
"wonka",
"@reasonml-community/graphql-ppx"
],
"ppx-flags": ["@reasonml-community/graphql-ppx/ppx"]
}
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 graphql-ppx can use to type check your queries. You should check this file into version control and keep it updated as your API changes.
For additional help, head here.
`sh`
npx get-graphql-schema ENDPOINT_URL -j > graphql_schema.json
Simply re-run this script at anytime to regenerate the graphql_schema.json file according to your latest backend schema.
reason-urql has a nice set of examples showing how to use the hooks and client 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 steps.
`sh1. Navigate into the example of choice.
cd examples/1-execute-query-mutation
The example will start up at
http://localhost:3000. Edit the example freely to watch changes take effect.$3
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:`sh
Save your changes to source, then take the following steps.
1. Clean any artifacts from previous builds.
yarn clean2. Rebuild the source.
yarn build3. 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.Please help out by opening an issue or filing a PR.
This project follows the all contributors spec. Thanks to these wonderful folks for contributing (Emoji Key):
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!
[maintenance-image]: https://img.shields.io/badge/maintenance-experimental-blueviolet.svg