plugins/lisa-expo-agy/skills/apollo-client/SKILL.md
This skill should be used when writing or modifying GraphQL operations, hooks, or mutations using Apollo Client 3.10. It enforces best practices for optimistic responses, cache updates, and TypeScript type generation. Use this skill when creating new queries/mutations, reviewing Apollo code, or troubleshooting cache issues.
npx skillsauth add codyswanngt/lisa apollo-clientInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill provides best practices for Apollo Client 3.10 in this codebase, ensuring consistent patterns for GraphQL operations, optimistic UI updates, cache management, and TypeScript type safety.
After modifying any operations.graphql file, run the appropriate generator:
bun run generate:types:dev # Development environment
bun run generate:types:staging # Staging environment
bun run generate:types:production # Production environment
Note: Replace
bunwith your project's package manager (npm,yarn,pnpm) as needed.
All GraphQL types, hooks, and documents must come from generated types:
import {
useGetPlayerQuery,
useUpdatePlayerMutation,
GetPlayerQuery,
PlayerFragment,
ListPlayersDocument,
} from "@/generated/graphql";
Import all GraphQL-related types from @/generated/graphql. Never define manual TypeScript types for GraphQL entities.
// CORRECT
import { PlayerFragment, useUpdatePlayerMutation } from "@/generated/graphql";
// INCORRECT - Never do this
type Player = { id: string; name: string };
The generated/graphql.ts file is auto-generated by codegen. To change types:
operations.graphql file in the feature directorybun run generate:types:devAfter modifying any operations.graphql file, immediately run the generator before committing. Verify changes compile with bun run typecheck.
Every mutation must include an optimisticResponse for instant UI feedback:
const [updatePlayer] = useUpdatePlayerMutation({
optimisticResponse: variables => ({
__typename: "Mutation",
updatePlayer: {
__typename: "Player",
id: variables.id,
name: variables.input.name,
updatedAt: new Date().toISOString(),
},
}),
});
Key requirements:
__typename for every object in the responseid for cache normalizationcrypto.randomUUID())Every mutation must handle cache updates using one of these strategies:
Automatic Updates - When mutation returns the full entity with id and __typename, Apollo updates automatically. No extra code needed.
cache.modify - For adding/removing items from lists:
const [addPlayer] = useAddPlayerMutation({
optimisticResponse: {
/* ... */
},
update(cache, { data }) {
cache.modify({
fields: {
players(existingPlayers = [], { readField }) {
const newRef = cache.writeFragment({
data: data.addPlayer,
fragment: PlayerFragmentDoc,
});
return [...existingPlayers, newRef];
},
},
});
},
});
refetchQueries - Fallback for complex scenarios:
const [complexMutation] = useComplexMutation({
refetchQueries: ["ListPlayers"],
awaitRefetchQueries: true,
});
Define fragments before queries/mutations that use them:
# 1. Fragments first
fragment PlayerFragment on Player {
id
knownName
firstName
lastName
team {
id
name
}
}
# 2. Queries second
query GetPlayer($id: ID!) {
player(id: $id) {
...PlayerFragment
}
}
# 3. Mutations last
mutation UpdatePlayer($id: ID!, $input: UpdatePlayerInput!) {
updatePlayer(id: $id, input: $input) {
...PlayerFragment
}
}
Mutations must return all fields needed for cache updates:
mutation AddPlayerToKanban($input: AddPlayerToKanbanInput!) {
addPlayerToKanban(input: $input) {
id # Required for cache normalization
position
notes
kanbanPhaseId
kanbanPhase {
# Include related objects
id
name
}
createdAt
updatedAt
}
}
// Frequently changing data - balance speed and freshness
fetchPolicy: "cache-and-network";
// Stable reference data - prioritize cache
fetchPolicy: "cache-first";
// Always-fresh data - skip cache
fetchPolicy: "network-only";
const { data } = useGetPlayerQuery({
variables: { id: playerId! },
skip: !playerId,
});
Use onError callback instead of try/catch with console.log:
const [mutation] = useMutation(MUTATION, {
onError: error => {
setErrorState("Failed to update. Please try again.");
},
});
Reference references/mutation-patterns.md for comprehensive examples of the complete mutation pattern including optimistic responses, cache updates, and error handling.
When writing or reviewing Apollo code, verify:
@/generated/graphqloptimisticResponse__typename included in all optimistic response objectsid included in all optimistic response objectsfetchPolicyskip when variables may be undefinedonError callbackdevelopment
Prepare a machine — a fresh laptop or a throwaway container — to run coding agents, before any repository exists. Detects which of Lisa's supported agents (Claude Code, Codex, Cursor, OpenCode, Antigravity, Copilot) are already installed, asks which credential manager the machine uses (Bitwarden, 1Password, Doppler, Vault, AWS, or none), and installs only what is missing, each by its vendor's own preferred method. Idempotent, headless by default, and emits a Dockerfile for a spin-up/spin-down environment. Run it on a new machine, in a container, or before cloning anything.
tools
Provision and verify a remote execution environment for a host project — Codex Cloud today, other remote surfaces as they are added. Generates a repository-owned setup script that installs the declared toolchain, materializes secrets through lisa-secrets-access, and runs the project's own hook. Provisions by API where one exists, by driving the vendor console where one does not, and by emitting exact config otherwise — then proves the result with the same read-back regardless of which tier did the work. Use before dispatching any work with executionEnv.
tools
Bring a developer's machine in line with the toolchain the project declares. Reports every tool in remoteEnv.tools that is missing, outdated, or unpinned for this platform, and installs the missing ones into ~/.local/bin from the same pinned, checksummed entries the remote surfaces use — but only when asked. Same manifest, same pins, same installers as lisa-setup-remote-env; what differs is consent and that the pin is a floor rather than an equality. Run it on a fresh checkout, after a manifest change, or when a tool fails at the moment of use.
tools
Route one unit of work to a remote execution surface. Reads the executionEnv parameter (local by default, codex-cloud or claude-web today), verifies the environment is provisioned and bound to this repository, submits a thin skill invocation, records the task identifier to .lisa/remote-dispatch.json, and exits without polling. Routing only — the remote runs the identical skill from the identical repository. Composable and inline: other skills invoke it via the Skill tool rather than users calling it directly.