Last active
October 30, 2018 09:35
-
-
Save kamilkisiela/639f6c726272eaec91f98a899785d919 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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