URQL - Universal React Query Library (GraphQL Client)
Tags: graphql, react, webdev, beginners
Published: 2020-08-11 05:45:02

Universal React Query Library (URQL) is a highly customizable GraphQL client, exposed as a set of React components by [Formidable](https://formidable.com/), aiming to become a lightweight alternative that would uphold the principal values of the GraphQL protocol & SDL.

Currently, the most popular client libraries come with large API footprints. URQL's  main goal is to simplify some of the most popular aspects arising when using GraphQL by providing:

### 1. The Declarative Queries

URQL Client internally manages the lifetime and updates for query & mutation operations in the background:
- when a cache invalidates their results you may receive updated data,
- when your app stops being interested in results URQL will teardown the operation (it will stop requesting new data, stop updating results)

![URQL Declarative Queries](https://dev-to-uploads.s3.amazonaws.com/i/vr94ytzh0otcabjbuise.png)
Source: [Uql Docs](https://formidable.com/open-source/urql/docs/basics/getting-started/)

### 2. The abstracted caching

Caching is handled & customizable with so-called Exchanges. The default `cacheExchange` offers basic cache implementation that will avoid sending the same requests to a GraphQL API repeatedly by caching the result of each query. For more complex cases containing data interdependencies, URQL offers normalized caching provided by [`@urql/exchange-graphcache`](https://github.com/FormidableLabs/urql/tree/main/exchanges/graphcache) package.

### 3. The central point of extensibility and integration with GraphQL API

URQL provides `Exchanges` to abstract how the Client interacts with frameworks, GraphQL API, or your app. URQL's  `Exchanges` have access to all operations and all results (the concept is very similar to middlewares in Redux). The core package's default behaviors are implemented using Exchanges as both operations as their results are treated as a stream of events:

![URQL Extensibility provided by Exchanges](https://dev-to-uploads.s3.amazonaws.com/i/r01gwkb9equx86qz7gmf.png)
Source: [Uql Docs](https://formidable.com/open-source/urql/docs/basics/getting-started/)

## Features

- **Built to be easy to use** -  URQL prioritizes usability and adaptability aiming to be the first-choice pick for both, newcomers as well as GraphQL power-users,
- **Performant and functional** - Lightweight & powerful GraphQL client, easy to use with React, Preact, and Svelte, makes URQL a great alternative to other bulky GraphQL clients.
- **Logical default behavior and caching** - URQL enables you to use GraphQL in your apps out of the box without complex configurations, large API overhead, and all that fuss.
- **Easily extensible** - one of the most interesting concepts presented in URQL are *Exchanges*. They are a kind of middleware that will help you change how you fetch, cache, or subscribe to data.

## Basic Usage

The method `createClient` creates the GraphQL client which requires providing API's URL as a bare minimum. This Client will manage all your operations. To make it work in React & Preact provide it via the Context API with the help of the `Provider` export.

```react
import { createClient, Provider } from 'urql';
const client = createClient({
  url: 'http://localhost:3000/graphql',
});
const App = () => (
  <Provider value={client}>
    <YourRoutes />
  </Provider>
);
```
Source: [Uql Docs](https://formidable.com/open-source/urql/docs/basics/getting-started/)

To get more details instructions & exmaples makes sure to visit [official URQL documentation](https://formidable.com/open-source/urql/docs/).

---

## Speed up your GraphQL schema development

*GraphQL Editor* is a supportive tool for both advanced GraphQL users as well as those taking their first steps with GraphQL APIs. Our all-in-one development environment for GraphQL will help you build, manage & deploy your GraphQL API much faster. **[Try GraphQL Editor for free!](https://graphqleditor.com)**


[![GraphQL Editor](https://dev-to-uploads.s3.amazonaws.com/i/a7qwlawx8v594fs2bq0a.gif)](https://graphqleditor.com/)