GraphQL Editor LogoTry GraphQL Editor

URQL - Universal React Query Library (GraphQL Client)

August 11, 2020 by Tomek

Universal React Query Library (URQL) is a highly customizable GraphQL client, exposed as a set of React components by Formidable, 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 Source: Uql Docs

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 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 Source: Uql Docs

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.

import { createClient, Provider } from 'urql';
const client = createClient({
  url: 'http://localhost:3000/graphql',
});
const App = () => (
  <Provider value={client}>
    <YourRoutes />
  </Provider>
);

Source: Uql Docs

To get more details instructions & exmaples makes sure to visit official URQL documentation.


Speed up your GraphQL API development

The 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 thanks to dozens of built-in micro features. Its graphical interface will also fix communication within your product team. Visualization is the key!

Try it for free

Tomek Poniatowicz
Written by Tomek Poniatowicz GraphQL enthusiast. Magic the Gathering fanatic. Pizza monster. email me:[email protected]Twitter Shield
← Back to blog

Menu

© Copyright 2018 Graphqleditor.com