npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@urql/rescript

v4.0.0

Published

[![npm](https://img.shields.io/npm/v/@urql/rescript.svg)](https://www.npmjs.com/package/@urql/rescript) [![All Contributors](https://img.shields.io/badge/all_contributors-20-orange.svg)](#contributors) [![Build Status](https://github.com/FormidableLabs/re

Downloads

1,436

Readme

rescript-urql

npm All Contributors Build Status Maintenance Status

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

✨Features

  • ⚛️ A fully featured GraphQL client for rescript-react.
  • ✅ 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.

rescript-urql is a GraphQL client for rescript-react, 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 ReScript, with the benefits of a sound type system, blazing fast compilation, and opportunities for guided customization.

📋 Documentation

💾 Installation

1. Install @urql/rescript alongside its peerDependencies and devDependencies.

yarn add @urql/rescript 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 rescript-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:

"resolutions": {
  "wonka": "5.0.0-rc.1"
}

If you're using npm, you may need to stay on [email protected] until urql takes a dependency on wonka>=5.0.0.

2. Add @reasonml-community/graphql-ppx.

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.

yarn add @reasonml-community/graphql-ppx --dev

3. Update bsconfig.json.

Add @urql/rescript, wonka, and @reasonml-community/graphql-ppx to your bs-dependencies and @reasonml-community/graphql-ppx/ppx to your ppx_flags in bsconfig.json.

{
  "bs-dependencies": [
    "@urql/rescript",
    "wonka",
    "@reasonml-community/graphql-ppx"
  ],
  "ppx-flags": ["@reasonml-community/graphql-ppx/ppx"]
}

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 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.

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.

💻 Example Projects

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 at http://localhost:3000. Edit the example freely to watch changes take effect.

Editing rescript-urql source files

If developing on the main rescript-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 rescript-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):

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!