Skip to content
Development
Skill

/web-data-fetching-graphql-urql

URQL GraphQL client patterns — the exchange pipeline, document and normalized caching, queries, mutations, subscriptions, and authentication

From plugin
skills
26200 skills

Claude Code

$ npx -y skills add agents-inc/skills --skill web-data-fetching-graphql-urql --agent claude-code

SKILL.md

web-data-fetching-graphql-urql.SKILL.md
name: web-data-fetching-graphql-urql
description: URQL GraphQL client patterns — the exchange pipeline, document and normalized caching, queries, mutations, subscriptions, and authentication

URQL Patterns

> **Quick Guide:** URQL is a small core plus a pipeline of exchanges, and almost every configuration > question is really a question about that pipeline's order — synchronous exchanges before > asynchronous ones, error handlers before what they catch, `fetchExchange` last. Caching is > document-based by default, keyed on the query and its variables; normalized caching is an opt-in > exchange. Hooks return a `[result, execute]` tuple, and the loading flag is `fetching`.

**Detailed Resources:**

  • [examples/core.md](examples/core.md) — client and provider, `useQuery`, mutations, error handling, per-query context
  • [examples/exchanges.md](examples/exchanges.md) — the full pipeline, Graphcache config, auth with refresh, retry, custom exchanges
  • [examples/subscriptions.md](examples/subscriptions.md) — websocket setup, accumulating events, presence, cache updates from a subscription
  • [examples/v6-features.md](examples/v6-features.md) — the GET default, `preferGetMethod`, and the v4 → v6 migration steps
  • [reference.md](reference.md) — request policy and cache method tables, `CombinedError` shape, exchange catalogue

---

Which path applies

  • **Document caching** — the default `cacheExchange` from `urql`. A query plus its variables is one

cache entry, and a mutation invalidates every entry whose result shared a `__typename` with it. Nothing to configure, and no way to edit the cache by hand.

  • **Normalized caching** — the `cacheExchange` from `@urql/exchange-graphcache`, replacing the

default one. Entities are stored once by key, so `keys`, `updates`, `resolvers` and `optimistic` become available and mutations can edit the cache precisely. Adds roughly 8KB.

Start with the document cache. Move to Graphcache when a mutation needs to change a list the server did not return, or when you want optimistic updates.

---

<critical_requirements>

Before writing URQL code

**Order the exchanges: error handling, then synchronous, then asynchronous, with `fetchExchange` last.** An operation passes through them in array order, so a cache placed after a network exchange never sees a request, and an error handler placed after `authExchange` never sees a failed refresh.

**Put `__typename` in every optimistic response, along with every field a query reads.** Graphcache normalizes on `__typename` plus the key, and a field the optimistic object omits is a field the watching query cannot render.

**Set `preferGetMethod` to what the server accepts.** From v6 the client sends queries under 2048 characters as GET; `false` forces POST for everything, and `"force"` sends GET regardless of length.

</critical_requirements>

---

**Auto-detection:** `urql`, `@urql/core`, `@urql/exchange-graphcache`, `cacheExchange`, `fetchExchange`, `subscriptionExchange`, `mapExchange`, `ssrExchange`, `authExchange`, `retryExchange`, `useQuery`, `useMutation`, `useSubscription`, `requestPolicy`, `preferGetMethod`, `reexecuteQuery`, `CombinedError`, `wonka`

**Applies to:**

  • The exchange pipeline, its order, and writing an exchange
  • Document caching and normalized caching through Graphcache
  • Queries, mutations, optimistic updates and cache edits after a write
  • Real-time data over a subscription exchange
  • Authentication with token refresh, and retry policy

**Handled elsewhere:**

  • APIs addressed over REST — this client speaks one query language
  • Designing the schema and its resolvers; this skill consumes a schema
  • Client state that corresponds to no server field
  • Where errors are shipped once `mapExchange` has caught them

---

<philosophy>

Philosophy

The client itself does almost nothing: it turns a hook call into an operation and pushes it into a stream. Everything that looks like a feature — caching, auth, retries, deduplication, subscriptions, server rendering — is an exchange sitting in that stream, and every exchange sees the operation on the way out and the result on the way back.

Two things follow. Behaviour is added by installing an exchange rather than by configuring the client, so a project pays only for what it installs. And order is semantic rather than cosmetic: an exchange can only act on what has already reached it.

</philosophy>

---

<patterns>

Core patterns

Pattern 1: Client setup

import { Client, cacheExchange, fetchExchange } from "urql";

const client = new Client({
  url: GRAPHQL_ENDPOINT,
  exchanges: [cacheExchange, fetchExchange],
  requestPolicy: "cache-first",
});

`<Provider value={client}>` above the tree is what the hooks read; without it they throw at the first render rather than falling back to anything.

Full code: [examples/core.md](examples/core.md)

---

Pattern 2: Queries

const [result, reexecuteQuery] = useQuery<UsersData, UsersVariables>({
  query: USERS_QUERY,
  variables: { limit: DEFAULT_PAGE_SIZE },
  requestPolicy: "cache-and-network",
});

const { data, fetching, error, stale } = result;

if (fetching && !data) return <Skeleton />;
if (error && !data) return <Error message={error.message} />;

`fetching` is true for the first load and for every background refresh, so `fetching && !data` is what distinguishes them. `stale` marks cached data being revalidated — an "updating" hint rather than a spinner. `pause: !userId` holds a query back until its variables are real.

Default policy is `cache-first`; `cache-and-network` is the stale-while-revalidate one. The full table is in [reference.md](reference.md).

Full code: [examples/core.md](examples/core.md)

---

Pattern 3: Mutations

const [result, executeMutation] = useMutation<CreatePostData>(CREATE_POST);

const response = await executeMutation({ input });
if (response.error) return;

The execute function returns a promise c

Read more
@agents-inc
Ships withskills

The official skills marketplace for Agents Inc. 230+ skills covering everything from React and Prisma to Redis, ElevenLabs, and infrastructure tooling. Pick the skills that match your stack and install them via Claude Code. Need more control?

Stars on GitHub

Momentum

stars in total
26
Star history of agents-inc/skills on GitHub, a chart by star-history.com

Other skills on skills.

ai-infrastructure-litellm

ai-infrastructure-lite…

LiteLLM proxy server setup, TypeScript client patterns via OpenAI SDK, model routing, fallbacks, load balancing, spend tracking,…

@agents-inc@agents-incInstall Skill
ai-infrastructure-modal

ai-infrastructure-moda…

Serverless GPU compute platform for AI model deployment — web endpoints, GPU functions, model serving, and TypeScript client…

@agents-inc@agents-incInstall Skill
ai-infrastructure-ollama

ai-infrastructure-olla…

Local LLM inference with the Ollama JavaScript client -- chat, streaming, tool calling, vision, embeddings, structured output,…

@agents-inc@agents-incInstall Skill

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills10d309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc12d293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react1d252k
@facebook@facebookInstall Skill

Questions about web-data-fetching-graphql-urql.

Which coding agents can use web-data-fetching-graphql-urql?
web-data-fetching-graphql-urql installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.