urql

urql 专家服务,urql 是一款高度可定制且轻量的 GraphQL 客户端,适用于 React、Vue、Svelte 与原生 JavaScript。可帮助以最小包体积获取 GraphQL 数据,支持文档缓存、通过 Graphcache 实现的规范化缓存、交换器(middleware/links)机制、订阅与离线支持,是比 Apollo Client 更精简且更易扩展的替代方案。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "urql":https://skillpi.com/zh/skills/deepskill-534f562bcdbf71a0dd73098fa9f16a96bba0cf3d6056ac1c77934ea5a9e4cb98。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

urql 专家服务,urql 是一款高度可定制且轻量的 GraphQL 客户端,适用于 React、Vue、Svelte 与原生 JavaScript。可帮助以最小包体积获取 GraphQL 数据,支持文档缓存、通过 Graphcache 实现的规范化缓存、交换器(middleware/links)机制、订阅与离线支持,是比 Apollo Client 更精简且更易扩展的替代方案。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: urql
description: >-
  You are an expert in urql, the highly customizable and lightweight GraphQL
  client for React, Vue, Svelte, and vanilla JavaScript. You help developers
  fetch GraphQL data with minimal bundle size, document caching, normalized
  caching via Graphcache, exchanges (middleware pipeline), subscriptions, and
  offline support — providing a leaner alternative to Apollo Client with
  better extensibility.
license: Apache-2.0
compatibility: ''
metadata:
  author: terminal-skills
  version: 1.0.0
  category: Frontend Development
  tags:
    - graphql
    - react
    - client
    - lightweight
    - cache
    - exchange
    - typescript

urql — Lightweight GraphQL Client

You are an expert in urql, the highly customizable and lightweight GraphQL client for React, Vue, Svelte, and vanilla JavaScript. You help developers fetch GraphQL data with minimal bundle size, document caching, normalized caching via Graphcache, exchanges (middleware pipeline), subscriptions, and offline support — providing a leaner alternative to Apollo Client with better extensibility.

Core Capabilities

Setup and Queries

import { Client, Provider, cacheExchange, fetchExchange, gql, useQuery, useMutation } from "urql";

const client = new Client({
  url: "https://api.example.com/graphql",
  exchanges: [cacheExchange, fetchExchange],
  fetchOptions: () => ({
    headers: { Authorization: `Bearer ${getToken()}` },
  }),
});

function App() {
  return <Provider value={client}><Dashboard /></Provider>;
}

const POSTS_QUERY = gql`
  query Posts($limit: Int!) {
    posts(limit: $limit) { id title author { name } createdAt }
  }
`;

function PostList() {
  const [result, reexecute] = useQuery({
    query: POSTS_QUERY,
    variables: { limit: 10 },
  });

  const { data, fetching, error } = result;
  if (fetching) return <Spinner />;
  if (error) return <Error message={error.message} />;
  return (
    <div>
      {data.posts.map(p => <PostCard key={p.id} post={p} />)}
      <button onClick={() => reexecute({ requestPolicy: "network-only" })}>Refresh</button>
    </div>
  );
}

Mutations

const CREATE_POST = gql`
  mutation CreatePost($input: CreatePostInput!) {
    createPost(input: $input) { id title createdAt }
  }
`;

function CreatePostForm() {
  const [result, createPost] = useMutation(CREATE_POST);

  const handleSubmit = (data: any) => {
    createPost({ input: data }).then(result => {
      if (result.error) console.error(result.error);
    });
  };

  return <Form onSubmit={handleSubmit} loading={result.fetching} />;
}

Graphcache (Normalized Cache)

import { cacheExchange } from "@urql/exchange-graphcache";

const cache = cacheExchange({
  keys: { Post: (data) => data.id as string },
  resolvers: {
    Query: {
      post: (_, args) => ({ __typename: "Post", id: args.id }),
    },
  },
  updates: {
    Mutation: {
      createPost(result, _args, cache) {
        cache.updateQuery({ query: POSTS_QUERY, variables: { limit: 10 } }, (data) => {
          if (data) data.posts.unshift(result.createPost);
          return data;
        });
      },
    },
  },
});

Installation

npm install urql graphql
npm install @urql/exchange-graphcache     # Optional normalized cache

Best Practices

  1. Document cache — Default cache deduplicates by query+variables; sufficient for most apps
  2. Graphcache for complex — Use normalized cache only when you need cache updates across queries
  3. Exchanges — urql's middleware pipeline; add auth, retry, persist, logging as composable exchanges
  4. Request policies — Use cache-first (default), network-only for refresh, cache-and-network for stale-while-revalidate
  5. Bundle size — urql core is ~5KB gzipped (vs Apollo ~30KB); ideal for performance-sensitive apps
  6. SSR support — Use ssrExchange for server-side rendering; hydrates cache on client
  7. Subscriptions — Add subscriptionExchange for WebSocket/SSE subscriptions; plug and play
  8. Framework agnostic — Works with React, Vue, Svelte, and vanilla JS; same core, different bindings

当前收录版本

1.0.0

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • urql 是前端 GraphQL 开发的高频刚需工具,文档覆盖核心能力与最佳实践
  • 提供轻量级替代 Apollo Client 的明确价值主张,适合性能敏感场景
触发精准95/100

亮点

  • 触发词精准覆盖 urql 核心概念:cache、exchange、Graphcache、subscriptions
  • description 位置正确且内容完整,边界清晰无歧义
结构规范95/100

待提升项

  • 缺少 When to Use 显式章节 原报告严重程度:轻微

    文档未设置独立的 When to Use 章节说明适用场景

    改进建议:建议添加 When to Use 章节,明确说明何时选择 urql 而非其他 GraphQL 客户端

亮点

  • 结构清晰:Setup → Queries → Mutations → Graphcache → Installation → Best Practices
  • 提供完整端到端代码示例,frontmatter 元数据完整规范
执行可靠90/100

亮点

  • 工具来源明确(urql 官方包),参数配置正确
  • 覆盖主要异常状态(fetching/error),mutation 有错误处理机制
证据可验 (前四项均值)93/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

  • 安装或获取外部依赖

    使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。

    主文档提及 · 第 123, 124 行
文档引用的域名或地址

这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。

  • api.example.com

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。