- Notifications
You must be signed in to change notification settings - Fork27
ReScript bindings for Formidable's Universal React Query Library, urql.
License
teamwalnut/rescript-urql
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
![Maintenance Status][maintenance-image]
ReScript bindings for Formidable's Universal React Query Library,urql.
📣 Please note these bindings were previously maintained by Formidable, but have since been taken over by the ReScript Brazil community.
- ⚛️ A fully featured GraphQL client for
rescript-react. - ✅ Compile time type and schema validation.
- ⚙️ Customizable behavior via
exchanges. - 🎣 Support for
useQuery,useMutation,useSubscription, anduseClienthooks! - ⚡ Support for server-side rendering with Next.js.
rescript-urql is a GraphQL client forrescript-react, allowing you to hook up your components to queries, mutations, and subscriptions. It provides bindings tourql that allow you to use the API in ReScript, with the benefits of a sound type system, blazing fast compilation, and opportunities for guided customization.
yarn add @urql/rescript urql graphqlyarn add gentype --dev
We try to keep our bindings as close to latesturql as possible. However,urql tends to make releases a bit ahead ofrescript-urql. To get a compatible version, we recommend always staying strictly within this project'speerDependency range forurql.
ThegentypedevDependency is a requirement introduced byurql's use ofwonka.wonka's source uses@genType declarations, so when the BuckleScript / ReScript compiler attempts to compilewonka in your project, it'll need a local copy ofgentype to use.
If usingbs-platform>=8.0.0 you'll need to useyarn resolutions to specify a specific version ofwonka to resolve.urql has an explicit dependency on latestwonkav4, which is incompatible withbs-platform>=8.0.0. Seethis issue for more details.
In yourpackage.json, add the following:
"resolutions": {"wonka":"5.0.0-rc.1"}
If you're usingnpm, you may need to stay onbs-platform@7.3.2 untilurql takes a dependency onwonka>=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'sdevDependencies.
yarn add @reasonml-community/graphql-ppx --dev
Add@urql/rescript,wonka, and@reasonml-community/graphql-ppx to yourbs-dependencies and@reasonml-community/graphql-ppx/ppx to yourppx_flags inbsconfig.json.
{"bs-dependencies": ["@urql/rescript","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 likegraphql-cli. You should generate a file calledgraphql_schema.json at the root of your project thatgraphql-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, headhere.
npx get-graphql-schema ENDPOINT_URL -j> graphql_schema.jsonSimply re-run this script at anytime to regenerate thegraphql_schema.json file according to your latest backend schema.
rescript-urql has a nice set of examples showing how to use the hooks and client APIs to get the most out of GraphQL and ReScript in your app – check them out in the/examples folder. To run any of the examples, follow these 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 athttp://localhost:3000. Edit the example freely to watch changes take effect.
If developing on the mainrescript-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-queryyarn cleanyarn
Since we arelinking the examples' dependency onrescript-urql to thesrc directory, it's important to clean builds between changes to prevent any stale or erroneous artifacts.
Please help out byopening an issue orfiling a PR.
This project follows theall contributors spec. Thanks to these wonderful folks for contributing (Emoji Key):
About
ReScript bindings for Formidable's Universal React Query Library, urql.
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.