import gql from 'graphql-tag' import { graphql, compose } from 'react-apollo' const GetUser = gql` query GetUser() { getUser() { } }` const PutUser = gql` mutation PutUser($userUpdateForm: UserUpdateFormInput! , $userId: String) { putUser(userUpdateForm: $userUpdateForm, userId: $userId) { id firstName lastName email city province country birthdate sex role stravaToken createdAt updatedAt deletedAt } }` const DeleteUser = gql` mutation DeleteUser($userId: String) { deleteUser(userId: $userId) { id firstName lastName email city province country birthdate sex role stravaToken createdAt updatedAt deletedAt } }` const withAppSyncUser = compose( graphql(GetUser, { name: 'getUser', options: (ownProps) => ({ fetchPolicy: 'cache-and-network', variables: { } }), props: (props) => { if (props.getUser.error) console.log(props.getUser.error) return props } }), graphql(PutUser, { props: (props) => ({ putUser: ownProps => props.mutate({ variables: { userUpdateForm: ownProps.userUpdateForm, userId: ownProps.userId }, optimisticResponse: () => ({ putUser: { ...ownProps.user, __typename: 'User', version: 1 } }) }) }) }), graphql(DeleteUser, { props: (props) => ({ deleteUser: ownProps => props.mutate({ variables: { userId: ownProps.userId }, optimisticResponse: () => ({ deleteUser: { ...ownProps, __typename: 'User', version: 1 } }) }) }) }) ) export { GetUser, PutUser, DeleteUser, withAppSyncUser }