Skip to content

Instantly share code, notes, and snippets.

@dobleuber
Last active December 24, 2017 08:53
Show Gist options
  • Save dobleuber/c74625704c37d7245b747d31b3c433cc to your computer and use it in GitHub Desktop.
Save dobleuber/c74625704c37d7245b747d31b3c433cc to your computer and use it in GitHub Desktop.
Relay problem UI is no updated
const mutation = graphql`
mutation UpdateUserObjectSelectionMutation($input: UpdateUserObjectSelectionInput!) {
updateUserObjectSelection(input: $input) {
UserObjectSelection {
id
}
SelectItem {
id
}
}
}
`;
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
}
}
`);
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>;
}}
///
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment