urql
The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
A lightweight JavaScript library for connecting React, Vue, Svelte, and other front-end frameworks to a GraphQL API, with built-in caching and a flexible plugin system called exchanges.
urql is a JavaScript library for connecting front-end applications to a GraphQL API. GraphQL is a way for a web app to request exactly the data it needs from a server, rather than getting a fixed response format. urql handles the mechanics of sending those requests, caching the results, and delivering the data to your components.
The library works with several popular JavaScript frameworks out of a single package: React, Preact, Vue, Solid, and Svelte are all supported. Out of the box it uses a straightforward document cache, meaning it stores results for queries you have already run and skips the network call if the same query is made again. For applications with more complex data requirements, an optional add-on called Graphcache provides normalized caching, which keeps a more structured local copy of your data and can automatically update related parts of the UI when something changes.
Customization in urql is done through a concept called exchanges. Exchanges are small units of logic that sit in the request pipeline, and you can add, remove, or replace them to change how the client behaves. This makes it possible to add things like authentication headers, retry logic, or custom caching strategies without modifying the core library.
The project was founded by Formidable and is now maintained by its own open-source team. Documentation is organized into sections for beginners through to advanced users, and a browser extension is available to help inspect and debug GraphQL traffic from within developer tools. The readme for this repository is short and mostly points to the external documentation site.
Where it fits
- Connect a React app to a GraphQL API and automatically cache query results so repeated requests skip the network call.
- Add authentication headers to every GraphQL request in a Vue or Svelte app by writing a custom exchange plugin.
- Inspect and debug GraphQL traffic in the browser using the urql developer tools browser extension.