graphql-typescript-integration

graphql-typescript-integration is a cursor rule for Cursor from holtwood/awesome-cursorrules-zh. It costs 0 tokens per session (654 once invoked), scanned A, original, MIT.

A TypeScript rule for GraphQL operations that uses the API schema and queries to generate types. It helps type-check data and variables from the GraphQL server through to React components.

In plain words
What is it for?
Use it when generating TypeScript definitions for GraphQL queries, mutations, and subscriptions, and when typing Apollo hooks such as useQuery and useMutation.
Why use it?
It catches mismatched fields and variables during development instead of leaving them to fail at runtime.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/holtwood/awesome-cursorrules-zh/graphql-typescript-integration
Clone the repo
git clone --depth 1 https://github.com/holtwood/awesome-cursorrules-zh

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for graphql-typescript-integration

README.md
[![agentmods](https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/graphql-typescript-integration.svg)](https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/graphql-typescript-integration)
Your own site
<a href="https://agentmods.dev/rules/holtwood/awesome-cursorrules-zh/graphql-typescript-integration"><img src="https://agentmods.dev/badge/rules/holtwood/awesome-cursorrules-zh/graphql-typescript-integration.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 654 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00654
Opus 5 $0.00000 $0.00327
Sonnet 5 $0.00000 $0.00131
Haiku 4.5 $0.00000 $0.00065

Measured 2d ago against content hash 2d3495012769, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

graphql-typescript-integration scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/rules/frontend/react/apollo-graphql/graphql-typescript-integration.mdc · 80 lines

What it actually says

  • 对 GraphQL 操作使用 TypeScript 确保类型安全
    • 代码生成:利用 GraphQL Code Generator 或类似工具,根据 GraphQL schema 和操作(Queries, Mutations, Subscriptions)自动生成 TypeScript 类型定义。
    • 类型推断:确保 useQueryuseMutationuseSubscription Hooks 的返回值(data, loading, error)和变量(variables)都具有正确的类型推断。
    • 端到端类型安全:从 GraphQL API 到前端组件,实现端到端的类型安全,减少运行时错误。
    • 示例
      // graphql.schema.json (部分)
      {
        "data": {
          "__schema": {
            "types": [
              {
                "kind": "OBJECT",
                "name": "User",
                "fields": [
                  { "name": "id", "type": { "kind": "NON_NULL", "ofType": { "kind": "SCALAR", "name": "ID" } } },
                  { "name": "name", "type": { "kind": "SCALAR", "name": "String" } }
                ]
              }
            ]
          }
        }
      }
      
      // query.graphql
      query GetUser($id: ID!) {
        user(id: $id) {
          id
          name
        }
      }
      
      // generated.ts (通过工具生成)
      export type GetUserQueryVariables = {
        id: string;
      };
      
      export type GetUserQuery = {
        user?:  {
          __typename?: "User";
          id: string;
          name?: string | null;
        } | null;
      };
      
      // component.tsx
      import { useQuery } from '@apollo/client';
      import { GetUserQuery, GetUserQueryVariables } from './generated'; // 假设类型已生成
      
      const GET_USER_QUERY = gql`
        query GetUser($id: ID!) {
          user(id: $id) {
            id
            name
          }
        }
      `;
      
      function UserProfile({ userId }: { userId: string }) {
        const { data, loading, error } = useQuery<GetUserQuery, GetUserQueryVariables>(GET_USER_QUERY, {
          variables: { id: userId },
        });
      
        if (loading) return <p>Loading...</p>;
        if (error) return <p>Error: {error.message}</p>;
      
        return (
          <div>
            <h1>{data?.user?.name}</h1>
            <p>ID: {data?.user?.id}</p>
          </div>
        );
      }
      
    • 手动类型定义(不推荐):在无法使用代码生成工具的情况下,可以手动定义 GraphQL 响应的 TypeScript 接口,但这容易出错且难以维护。
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 80 lines · 0 tokens per session scan A 2d3495012769

Subscribe to this mod's changes

graphql-typescript-integration is a cursor rule published in the GitHub repository holtwood/awesome-cursorrules-zh (232 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 654 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.