graphql(createUserGql, { props: ({ mutate }) => ({ mutations: { signUp: ({ firstName, lastName, email, password }) => mutate({ variables: { firstName, lastName, email, password } }) } }) })
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] }); } } }) } }) })
graphql(upvotePostGql, { props: ({ ownProps, mutate }) => ({ upvote: (id, votes) => mutate({ variables: { id, votes }, optimisticResponse: { __typename: 'Mutation', updatePost: { __typename: 'Post', id: ownProps.id, votes: ownProps.votes + 1 } } }) }) })
compose( graphql(UPDATE_CARD_ORDER, { props: ({ mutate }) => ({ updateCard: (order, id) => mutate({ variables: { order, id }, }), }), }), DragDropContext(HTML5Backend), )(CardContainer)
graphql(loginMutation, { props: ({ ownProps, mutate }) => ({ handleLogin: (email, password) => { mutate({ variables: { email: email, password: password } }) .then(({ data: { login } }) => { console.log('Response OK') console.log(login); return Promise.resolve(); }) .catch((error) => { console.log(error); return Promise.reject(); }) }, }) })(LoginContainer)
graphql(LEAVE_GROUP_MUTATION, { props: ({ ownProps, mutate }) => ({ leaveGroup: ({ id }) => mutate({ variables: { id }, update: (store, { data: { leaveGroup } }) => { // Read the data from our cache for this query. const data = store.readQuery({ query: USER_QUERY, variables: { id: ownProps.auth.id } }); // Add our message from the mutation to the end. data.user.groups = data.user.groups.filter(g => leaveGroup.id !== g.id); // Write our data back to the cache. store.writeQuery({ query: USER_QUERY, variables: { id: ownProps.auth.id }, data, }); }, }), }), })
graphql(logout, { props: ({ mutate }) => ({ logout: () => mutate({ update: (proxy, { data }) => { // Clear session persist.willRemoveSessionToken() // Read the data from our cache for this query. let cached = proxy.readQuery({ query: userProfile }) // Errors cached.errors = data.errors // User cached.user = data.logout.user ? data.logout.user : { _id: null, name: null, status: null, __typename: 'User' } // Authen cached.authen = { isLoggedIn: data.logout.isLoggedIn, sessionToken: data.logout.sessionToken, __typename: 'Authen' } // Write our data back to the cache. proxy.writeQuery({ query: userProfile, data: cached }) } }) }) })(Logout)
graphql(forget, { props: ({ mutate }) => ({ forget: (email) => mutate({ variables: { email }, update: (proxy, { data }) => { // Read the data from our cache for this query. let cached = proxy.readQuery({ query: userProfile }) // Errors cached.errors = data.errors // User cached.user = cached.user || { _id: null, name: null, status: null, __typename: 'User' } cached.user.status = data.forget.status // Write our data back to the cache. proxy.writeQuery({ query: userProfile, data: cached }) } }) }) })(Forget)
graphql(CREATE_GROUP_MUTATION, { props: ({ ownProps, mutate }) => ({ createGroup: group => mutate({ variables: { group }, update: (store, { data: { createGroup } }) => { // Read the data from our cache for this query. const data = store.readQuery({ query: USER_QUERY, variables: { id: ownProps.auth.id } }); // Add our message from the mutation to the end. data.user.groups.push(createGroup); // Write our data back to the cache. store.writeQuery({ query: USER_QUERY, variables: { id: ownProps.auth.id }, data, }); }, }), }), })
graphql(CREATE_CARD, { props: ({ mutate }) => ({ createCard: (content, name, order) => mutate({ variables: { content, name, order }, optimisticResponse: { __typename: 'Mutation', createCard: { id: 'abc123', __typename: 'Card', content, name, order, }, }, update: (store, { data: { createCard } }) => { // Read the data from our cache for this query. const data = store.readQuery({ query: ALL_CARDS }); // Add our comment from the mutation to the end. data.allCards.push(createCard); // Write our data back to the cache. store.writeQuery({ query: ALL_CARDS, data }); }, }), }), })(CreateCard)
graphql(signInGql, { props: ({ mutate }) => ({ mutations: { signIn: ({ email, password }) => mutate({ variables: { email, password } }) } }) })
graphql(CREATE_GROUP_MUTATION, { props: ({ ownProps, mutate }) => ({ createGroup: group => mutate({ variables: { group }, update: (store, { data: { createGroup } }) => { // Read the data from our cache for this query. const data = store.readQuery({ query: USER_QUERY, variables: { id: ownProps.auth.id } }); // Add our message from the mutation to the end. data.user.groups.push(createGroup); // Write our data back to the cache. store.writeQuery({ query: USER_QUERY, variables: { id: ownProps.auth.id }, data, }); }, }), }), })
graphql(DELETE_GROUP_MUTATION, { props: ({ ownProps, mutate }) => ({ deleteGroup: id => mutate({ variables: { id }, update: (store, { data: { deleteGroup } }) => { // Read the data from our cache for this query. const data = store.readQuery({ query: USER_QUERY, variables: { id: ownProps.auth.id } }); // Add our message from the mutation to the end. data.user.groups = data.user.groups.filter(g => deleteGroup.id !== g.id); // Write our data back to the cache. store.writeQuery({ query: USER_QUERY, variables: { id: ownProps.auth.id }, data, }); }, }), }), })
graphql(DELETE_GROUP_MUTATION, { props: ({ ownProps, mutate }) => ({ deleteGroup: id => mutate({ variables: { id }, update: (store, { data: { deleteGroup } }) => { // Read the data from our cache for this query. const data = store.readQuery({ query: USER_QUERY, variables: { id: ownProps.auth.id } }); // Add our message from the mutation to the end. data.user.groups = data.user.groups.filter(g => deleteGroup.id !== g.id); // Write our data back to the cache. store.writeQuery({ query: USER_QUERY, variables: { id: ownProps.auth.id }, data, }); }, }), }), })
graphql(LEAVE_GROUP_MUTATION, { props: ({ ownProps, mutate }) => ({ leaveGroup: ({ id }) => mutate({ variables: { id }, update: (store, { data: { leaveGroup } }) => { // Read the data from our cache for this query. const data = store.readQuery({ query: USER_QUERY, variables: { id: ownProps.auth.id } }); // Add our message from the mutation to the end. data.user.groups = data.user.groups.filter(g => leaveGroup.id !== g.id); // Write our data back to the cache. store.writeQuery({ query: USER_QUERY, variables: { id: ownProps.auth.id }, data, }); }, }), }), })