Agent skill
graphql-best-practices
Best practices for using GraphQL and Apollo Client in the project to avoid common errors.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/graphql-best-practices
SKILL.md
GraphQL & Apollo Client Best Practices
This skill outlines the mandatory patterns for implementing GraphQL features in this project to avoid "Invalid hook call" errors and import issues.
1. Wrapping Components with ApolloProvider
Context:
In Astro's island architecture, React components (.tsx) running on the client (hydrated islands) do not share a specific global context unless explicitly provided. This rule does not apply to .astro files where data fetching happens server-side using the client instance directly.
Rule:
When a React component uses Apollo hooks (e.g., useQuery, useMutation), you MUST serve it wrapped in an ApolloProvider specifically for that island.
Implementation Pattern:
Separation of specific logic (Content) and the Provider wrapper.
import React, { useState } from 'react';
import { ApolloProvider } from '@apollo/client';
import { clientGql } from '@graphql-astro/apolloClient';
import { useSomeQuery } from '@graphql-astro/generated/graphql';
// 1. Inner component with the logic/hooks
function MyComponentContent() {
const { data, loading } = useSomeQuery();
if (loading) return <div>Loading...</div>;
return <div>{data?.someField}</div>;
}
// 2. Exported component wrapped with provider
function MyComponent() {
return (
<ApolloProvider client={clientGql}>
<MyComponentContent />
</ApolloProvider>
);
}
export default MyComponent;
2. Imports in graphql.ts
Rule:
If you need to use gql tag manually or in graphql.ts (or similar utility files), you MUST import it from @apollo/client/core.
Correct:
import { gql } from '@apollo/client/core';
Incorrect:
import { gql } from '@apollo/client';
import { gql } from 'graphql-tag';
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?