import gql from 'graphql-tag' import { graphql, compose } from 'react-apollo' const PostTime = gql` mutation PostTime($timeMinimal: TimeMinimalInput! ) { postTime(timeMinimal: $timeMinimal) { id distance time createdAt updatedAt } }` const GetTime = gql` query GetTime() { getTime() { } }` const GetTime = gql` query GetTime($id: Int) { getTime(id: $id) { id distance time createdAt updatedAt } }` const PatchTime = gql` mutation PatchTime($timePatchEntry: TimePatchEntryInput! ) { patchTime(timePatchEntry: $timePatchEntry) { id distance time createdAt updatedAt } }` const DeleteTime = gql` mutation DeleteTime($id: Int) { deleteTime(id: $id) { id distance time createdAt updatedAt } }` const withAppSyncTime = compose( graphql(GetTime, { name: 'getTime', options: (ownProps) => ({ fetchPolicy: 'cache-and-network', variables: { } }), props: (props) => { if (props.getTime.error) console.log(props.getTime.error) return props } }) graphql(DeleteTime, { props: (props) => ({ deleteTime: ownProps => props.mutate({ variables: { id: ownProps.id }, optimisticResponse: () => ({ deleteTime: { ...ownProps, __typename: 'Time', version: 1 } }) }) }) }) ) export { PostTime, GetTime, GetTime, PatchTime, DeleteTime, withAppSyncTime }