Skip to content

Instantly share code, notes, and snippets.

@kamilkisiela
Last active October 30, 2018 09:35
Show Gist options
  • Save kamilkisiela/639f6c726272eaec91f98a899785d919 to your computer and use it in GitHub Desktop.
Save kamilkisiela/639f6c726272eaec91f98a899785d919 to your computer and use it in GitHub Desktop.
import { mutation } from '@loona/react';
export class BooksState {
@mutation('addBook')
addBook(args, context) {
// our new book
const book = {
id: generateRandomId(),
title: args.title,
__typename: 'Book',
};
// updates the store with help of Immer
context.patchQuery(
gql`
{
books {
id
title
}
}
`,
data => {
data.books.push(book);
},
);
return book;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment