relay-mutations-patterns

Implement Relay mutations with optimistic updates and connection-based cache updates.

187|20|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/TheBushidoCollective/han --skill relay-mutations-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: relay-mutations-patterns
Source: https://github.com/TheBushidoCollective/han/tree/main/jutsu/jutsu-relay/skills/relay-mutations-patterns
Command: npx skills add https://github.com/TheBushidoCollective/han --skill relay-mutations-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill covers declarative Relay mutations, optimistic updates, and data consistency in UI.

Core Features & Use Cases

  • Basic Mutation: Creating or updating data via Relay mutations.
  • Optimistic Updates: Immediate UI feedback with optimistic responses and updaters.
  • Connections: Using @appendEdge and similar directives for lists.

Quick Start

Implement a createPost mutation with optimisticResponse.

Frequently Asked Questions about relay-mutations-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement optimistic updates in Relay mutations?

Optimistic updates in Relay mutations provide immediate UI feedback by specifying an optimisticResponse in commitMutation or useMutation, which reflects changes before the server responds. Use optimisticUpdater to modify the normalized cache directly, ensuring the UI updates instantly while the mutation completes in the background.

What's the best way to handle mutation errors and rollback in Relay?

Relay mutations support error handling through onError and onCompleted callbacks in commitMutation. On failure, the optimistic update automatically rolls back to the previous cache state, restoring the UI to its pre-mutation condition without manual intervention.

How do I update connection lists when creating or modifying items with Relay mutations?

Use @appendEdge and @connection directives to automatically manage list updates in Relay mutations. These directives handle adding new edges to connections and maintaining proper list ordering, eliminating manual cache updates for collection-based mutations like createPost or createComment.

Can I use Relay mutations with React hooks?

Yes, Relay provides useMutation hook for functional components, offering the same mutation capabilities as commitMutation with a hooks-based API. useMutation integrates seamlessly with Relay's normalized cache and supports optimisticResponse, optimisticUpdater, and error handling.

Do I need to write custom cache updaters for every Relay mutation?

No, Relay's @appendEdge and @connection directives automate cache updates for connection-based mutations. Custom optimisticUpdater functions are only necessary for complex mutations requiring non-standard cache manipulation beyond standard edge insertion.

How does Relay's normalized cache work with mutation optimistic responses?

Relay's normalized cache stores entities by type and ID, allowing optimisticResponse to instantly update all UI components referencing that entity. The optimisticUpdater can modify connections and relationships, with automatic rollback if the mutation fails server-side.