UNPKG

ran-boilerplate

Version:

React . Apollo (GraphQL) . Next.js Toolkit

25 lines (22 loc) 700 B
import { graphql } from 'react-apollo'; import createPostGql from './createPost.gql'; export const withMutation = graphql(createPostGql, { props: ({ mutate }) => ({ mutations: { createPost: (title, url) => mutate({ variables: { title, url }, updateQueries: { allPosts: (previousResult, { mutationResult }) => { const newPost = mutationResult.data.createPost; return Object.assign({}, previousResult, { // Append the new post allPosts: [newPost, ...previousResult.allPosts] }); } } }) } }) }); export default comp => withMutation(comp);