Use when relay fragment composition, data masking, colocation, and container patterns for React applications.
View on GitHubTheBushidoCollective/han
jutsu-relay
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-relay/skills/relay-fragments-patterns/SKILL.md -a claude-code --skill relay-fragments-patternsInstallation paths:
.claude/skills/relay-fragments-patterns/# Relay Fragments Patterns
Master Relay's fragment composition for building maintainable React
applications with proper data dependencies and component colocation.
## Overview
Relay fragments enable component-level data declaration with automatic
composition, data masking, and optimal data fetching. Fragments colocate data
requirements with components for better maintainability.
## Installation and Setup
### Installing Relay
```bash
# Install Relay packages
npm install react-relay relay-runtime
# Install Relay compiler
npm install --save-dev relay-compiler babel-plugin-relay
# Install GraphQL
npm install graphql
```
### Relay Configuration
```javascript
// relay.config.js
module.exports = {
src: './src',
schema: './schema.graphql',
exclude: ['**/node_modules/**', '**/__mocks__/**', '**/__generated__/**'],
language: 'typescript',
artifactDirectory: './src/__generated__'
};
// package.json
{
"scripts": {
"relay": "relay-compiler",
"relay:watch": "relay-compiler --watch"
}
}
```
### Environment Setup
```javascript
// RelayEnvironment.js
import {
Environment,
Network,
RecordSource,
Store
} from 'relay-runtime';
function fetchQuery(operation, variables) {
return fetch('http://localhost:4000/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${localStorage.getItem('token')}`
},
body: JSON.stringify({
query: operation.text,
variables
})
}).then(response => response.json());
}
const environment = new Environment({
network: Network.create(fetchQuery),
store: new Store(new RecordSource())
});
export default environment;
```
## Core Patterns
### 1. Basic Fragment Definition
```javascript
// PostCard.jsx
import { graphql, useFragment } from 'react-relay';
const PostCardFragment = graphql`
fragment PostCard_post on Post {
id
title
excerpt
publishedAt
author {
name
avatar
}
}
`;
function Pos