import gql from 'graphql-tag' import { graphql, compose } from 'react-apollo' const PostUser = gql` mutation PostUser($userMinimal: UserMinimalInput! ) { postUser(userMinimal: $userMinimal) { } }` const PostUser = gql` mutation PostUser($userMinimal: UserMinimalInput! ) { postUser(userMinimal: $userMinimal) { id username role createdAt updatedAt } }` const GetUser = gql` query GetUser() { getUser() { } }` const GetUser = gql` query GetUser($id: Int) { getUser(id: $id) { id username role createdAt updatedAt } }` const PatchUser = gql` mutation PatchUser($userPatchEntry: UserPatchEntryInput! ) { patchUser(userPatchEntry: $userPatchEntry) { id username role createdAt updatedAt } }` const DeleteUser = gql` mutation DeleteUser($id: Int) { deleteUser(id: $id) { id username role createdAt updatedAt } }` 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(DeleteUser, { props: (props) => ({ deleteUser: ownProps => props.mutate({ variables: { id: ownProps.id }, optimisticResponse: () => ({ deleteUser: { ...ownProps, __typename: 'User', version: 1 } }) }) }) }) ) export { PostUser, PostUser, GetUser, GetUser, PatchUser, DeleteUser, withAppSyncUser }