Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

relay-mutation-store-updates

БесплатноБез исполняемых скриптовНе проверен

Use when writing `if (success) updateFetchKey()`, an `onRequestClose` handler, or any refetch after a mutation; when a setting modal handles both create and…

lablupот lablup★ 137 звёзд на GitHub

Об этом скилле

Relay Mutation → Store Updates

The rule this skill exists to enforce:

A refetch after an update mutation is a bug, not a refresh. Update mutations should return the changed fields so Relay patches the normalized store by id. Refetch only when list membership changes.

This skill is the detailed treatment: how to tell the cases apart, and what to do in each.

Activation Triggers

  • Writing or reviewing onRequestClose={(success) => { if (success) updateFetchKey(); }}
  • A modal takes a nullable *Frgmt prop and branches create vs update inside
  • Choosing the selection set of a mutation payload
  • "The list doesn't refresh after saving" / "why is it fetching twice?"

1. The decision table

Ask what changed, not did it succeed.

What the mutation changed What to do
Fields of an entity already in the store (update) Select the changed fields on the returned node. Relay merges by id. No refetch.
Same, but a changed field is in the list's filter/orderBy Still no refetch — patch the row. The row may stop matching the active filter, and that is accepted: the user should see the values they just edited on the row they touched, and every list carries a manual refresh (BAIFetchKeyButton) for re-evaluating the predicate.
Same, but the payload returns only ok/msg (legacy) Keep the refetch and comment why (§4). Nothing to merge.
List membership — a row added or removed (create/delete) Refetch the list (§6). Don't patch the connection.
Server-derived fields you did not send (computed status, timestamps) Select those too; refetch only if the server cannot return them (§7).

2. Update: fill the selection set

An update mutation must return the entity and every field the calling UI reads that the mutation could have changed. Relay merges the payload into the normalized record by id, and every component holding that fragment re-renders — with no extra network traffic.

# ❌ Payload carries no data, so the store goes stale
# and the caller is forced to requery the whole list.
modify_user(email: $email, props: $props) {
  ok
  msg
}
# ✅ Spread the fragment the UI actually reads, so the selection set
# cannot drift out of sync with the component.
modify_user(email: $email, props: $props) {
  ok
  msg
  user {
    id
    ...YourListRow_user # ← the fragment your list row already renders
  }
}

If the consumer has no reusable fragment, hand-list every field the UI reads. Relay keys normalized records by node id, but on types that implement Node the compiler adds id to the network operation automatically — writing it explicitly is a readability convention, not a correctness requirement. The real gaps are always missing fields, not a missing id.

⚠️ Partial coverage is worse than refetching

Dropping the refetch is only safe if the payload covers every field the UI reads that the mutation could change. A partial selection set gives you the worst of both: no refetch and no store update.

UserSettingModal demonstrates the trap. It sends groupIds and its fragment reads projects { edges { node { id } } }, but the mutation payload never selects projects — and the update path skips the refetch. Changing a user's project membership succeeds on the server and leaves the UI showing the old projects until a manual refresh.

Before removing a refetch, diff the two lists:

  1. Fields the component's fragment reads.
  2. Fields the mutation payload returns.

Anything in (1) that the mutation input can change and (2) omits is a stale-UI bug. Add it to the selection set — or keep the refetch and say why.

3. Is the node even available? Check the schema first

Most of this backend already returns the node; the frontend just isn't asking for it. Before concluding a refetch is required, grep the payload type in data/schema.graphql — if it has a node field, there is no excuse.

4. Legacy ok/msg mutations: keep the refetch

A handful of mutations (ModifyAgent, ModifyImage, ModifyKeyPair, ModifyScalingGroup, and the three Modify*ResourcePolicy) return only ok/msg. There is nothing for Relay to merge, so keep the refetch and move on — that is the accepted answer, not a gap to close. Leave a one-line comment saying the payload carries no node.

Do not open a migration to their node-returning successors as part of an unrelated change: it drags in backend version compatibility for little gain. If you are already rewriting one of these call sites for another reason

Полный SKILL.md на GitHub

Установить relay-mutation-store-updates в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл relay-mutation-store-updates?

Use when writing `if (success) updateFetchKey()`, an `onRequestClose` handler, or any refetch after a mutation; when a setting modal handles both create and update behind one fragment prop; when choosing a mutation's response selection set; or when debugging "the list doesn't refresh after saving" / "why is it fetching twice". Covers when Relay patches the normalized store on its own, and when a refetch is genuinely the right answer.

Как установить скилл relay-mutation-store-updates?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл relay-mutation-store-updates запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить relay-mutation-store-updates с