xiaohongshu
xiaohongshu
graphql-inspector-validate
Use when validating GraphQL operations/documents against a schema, checking query depth, complexity, or fragment usage.
Full skill instructions
Expert knowledge of GraphQL Inspector's validate command for checking operations and documents against a schema with configurable rules.
The validate command checks GraphQL operations (queries, mutations, subscriptions) and fragments against a schema. It catches errors like undefined fields, wrong argument types, and invalid fragment spreads before runtime.
# Validate operations against schema
npx @graphql-inspector/cli validate './src/**/*.graphql' './schema.graphql'
# Validate operations from TypeScript files
npx @graphql-inspector/cli validate './src/**/*.tsx' './schema.graphql'
# Validate with glob patterns
npx @graphql-inspector/cli validate './**/*.{graphql,gql}' './schema.graphql'
# Apollo Federation V1
npx @graphql-inspector/cli validate './operations/**/*.graphql' './schema.graphql' \
--federation
# Apollo Federation V2
npx @graphql-inspector/cli validate './operations/**/*.graphql' './schema.graphql' \
--federationV2
# AWS AppSync directives
npx @graphql-inspector/cli validate './operations/**/*.graphql' './schema.graphql' \
--aws
Prevent deeply nested queries that could cause performance issues:
# Fail if query depth exceeds 10
npx @graphql-inspector/cli validate './src/**/*.graphql' './schema.graphql' \
--maxDepth 10
Example violation:
# Depth of 8 - might exceed limit
query DeepQuery {
user { # 1
posts { # 2
author { # 3
followers { # 4
posts { # 5
comments { # 6
author { # 7
name # 8
}
}
}
}
}
}
}
}
Limit alias usage to prevent response explosion:
# Max 5 aliases per operation
npx @graphql-inspector/cli validate './src/**/*.graphql' './schema.graphql' \
--maxAliasCount 5
Example violation:
# 6 aliases - exceeds limit of 5
query TooManyAliases {
user1: user(id: "1") { name }
user2: user(id: "2") { name }
user3: user(id: "3") { name }
user4: user(id: "4") { name }
user5: user(id: "5") { name }
user6: user(id: "6") { name } # Exceeds limit
}
Limit directives to prevent abuse:
# Max 10 directives per operation
npx @graphql-inspector/cli validate './src/**/*.graphql' './schema.graphql' \
--maxDirectiveCount 10
Limit query complexity by token count:
# Max 1000 tokens per operation
npx @graphql-inspector/cli validate './src/**/*.graphql' './schema.graphql' \
--maxTokenCount 1000
Calculate and limit query complexity:
# Max complexity score of 100
npx @graphql-inspector/cli validate './src/**/*.graphql' './schema.graphql' \
--maxComplexityScore 100
Create .graphql-inspector.yaml:
validate:
schema: './schema.graphql'
documents: './src/**/*.graphql'
# Validation limits
maxDepth: 10
maxAliasCount: 5
maxDirectiveCount: 10
maxTokenCount: 1000
maxComplexityScore: 100
# Federation support
federation: false
federationV2: false
aws: false
Error: Cannot query field "unknownField" on type "User".
Fix: Check field name spelling or add field to schema.
Error: Argument "id" has invalid value "123".
Expected type "ID!", found "123" (String).
Fix: Use correct type for argument.
Error: Field "user" argument "id" of type "ID!" is required.
Fix: Provide required argument.
Error: Fragment "UserFields" cannot be spread here as objects of
type "Post" can never be of type "User".
Fix: Ensure fragment type matches spread location.
Warning: Fragment "UnusedFragment" is never used.
Fix: Remove or use the fragment.
name: Validate Operations
on:
pull_request:
paths:
- 'src/**/*.graphql'
- 'src/**/*.tsx'
- 'schema.graphql'
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Inspector
run: npm install -g @graphql-inspector/cli
- name: Validate operations
run: |
graphql-inspector validate \
'src/**/*.graphql' \
schema.graphql \
--maxDepth 10 \
--maxAliasCount 5
{
"husky": {
"hooks": {
"pre-commit": "graphql-inspector validate 'src/**/*.graphql' schema.graphql"
}
}
}
GraphQL Inspector can extract operations from various file types:
// Operations in template literals are detected
const GET_USER = gql`
query GetUser($id: ID!) {
user(id: $id) {
name
email
}
}
`;
// Tagged template literals in React files
import { gql } from '@apollo/client';
const USER_QUERY = gql`
query UserQuery {
currentUser {
id
name
}
}
`;
.graphql filesFor monorepos with multiple schemas:
# Validate against specific service schema
npx @graphql-inspector/cli validate \
'./packages/app/src/**/*.graphql' \
'./packages/api/schema.graphql'
# Validate against federated supergraph
npx @graphql-inspector/cli validate \
'./packages/web/src/**/*.graphql' \
'./supergraph.graphql' \
--federationV2
Start permissive, add stricter rules over time:
# Phase 1: Basic validation only
validate:
schema: './schema.graphql'
documents: './src/**/*.graphql'
# Phase 2: Add depth limiting
validate:
schema: './schema.graphql'
documents: './src/**/*.graphql'
maxDepth: 15
# Phase 3: Add complexity limits
validate:
schema: './schema.graphql'
documents: './src/**/*.graphql'
maxDepth: 10
maxAliasCount: 10
maxComplexityScore: 200
--federation or --federationV2 for Federation directives--aws for AppSync directivesgql\...``)xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience