私の現在のケースを表すこの要点を作成しました。 基本的に私は詳細があるオブジェクトを持っています。この詳細では、リストから選択したアイテムがあります。私は異なる種類のリストを持っています。 そして選択はユーザーとの関係も持っています。リレーの突然変異でUIが更新されない
私は選択したアイテムを変更するために突然変異を呼びます。突然変異は期待どおりに機能しますが、私のUIは時代遅れのままです。
https://gist.github.com/dobleuber/c74625704c37d7245b747d31b3c433cc
types.graphql
type User @model {
id
userObjectSelection: [UserObjectSelection!]!
}
type Object @model {
id
name
userObjectSelection: [UserObjectSelection!]!
selectionType: SelectionType!
}
type SelectionType @model {
id
items: [SelectItem!]!
objects: [Object!]!
}
type SelectItem @model {
id
name
selectionType: SelectionType!
userObjectSelection: [UserObjectSelection!]!
}
type UserObjectSelection @model {
id
user: User!
object: Object!
selectedItem: selectItem
}
ObjectPage.js
const query = graphql`
query ObjectPageQuery($objectId: ID!, $userObjectSelectionId: ID!) {
object: node(id: $objectId) {
...Object_object
}
selection: node(id: $userObjectSelectionId) {
...Object_selection
}
}
`;
changeSelectedItem (selectionId, itemId) {
mutateSelectedItem(selectionId, itemId,() => console.log('updated'));
}
///
render={({ error, props }) => {
if (error) {
return <div>{error.message}</div>;
} else if (props) {
return (
<div className="object-page">
<Item
object={props.object}
selection={props.selection}
onSelectItem={this.changeSelectedItem}
/>
</div>
);
}
return <div>Loading</div>;
}}
///
Object.js
const Object = ({ object, selection, onSelectItem }) => {
const {id} = object;
return (
<div>
<span>{id}</span>
<div className="item-list">
object.selectionType.items.edges.map(({ node }) => (
<Item
key={node.__id}
item={node}
userObjectSelectionId={selection.id}
onSelectCard={onSelectItem}
selectedItem={selection.item}
/>
))
</div>
</div>);
};
createFragmentContainer(Object, graphql`
fragment Object_story on Object {
details
selectionType {
id
items: {
edges: {
node {
...Item_item
}
}
}
}
}
fragment Object_selection on UserObjectSelection {
id
selectedItem: item {
...Item_selectedCard
}
}
`);
mutation.js
const mutation = graphql`
mutation UpdateUserObjectSelectionMutation($input: UpdateUserObjectSelectionInput!) {
updateUserObjectSelection(input: $input) {
UserObjectSelection {
id
}
SelectItem {
id
}
}
}
`;
状態を突然変異させると、どのようにしてコンポーネントが新しい小道具で再レンダリングされるべきかがわかりますか? – Hav
リレーがコンポーネントを店舗にラップし、その店舗が小道具によってコンポーネントに送信される – dobleUber
あなたもあなたの突然変異の実装も表示できますか?また、あなたのスキーマを見る限り、あなたのコードはリレー仕様に従わないようです。 connectionを使うつもりなら、PaginationContainerが必要です。あるいは単に項目のリストが必要な場合は、 'edges'と' node'ネストは存在しません。 – tkymtk