import gql from 'graphql-tag' import { graphql, compose } from 'react-apollo' const GetSegmentRating = gql` query GetSegmentRating($id: String) { getSegmentRating(id: $id) { id segmentId userId trafficRating surfaceRating surfaceType pathType createdAt updatedAt deletedAt } }` const PostSegmentRating = gql` mutation PostSegmentRating($segmentCreateForm: SegmentCreateFormInput! , $id: String, $currentZoomLevel: Int) { postSegmentRating(segmentCreateForm: $segmentCreateForm, id: $id, currentZoomLevel: $currentZoomLevel) { id name description polyline created_by hidden } }` const DeleteSegmentRating = gql` mutation DeleteSegmentRating($id: String) { deleteSegmentRating(id: $id) { } }` const withAppSyncSegmentRating = compose( graphql(GetSegmentRating, { name: 'getSegmentRating', options: (ownProps) => ({ fetchPolicy: 'cache-and-network', variables: { id: ownProps.id } }), props: (props) => { if (props.getSegmentRating.error) console.log(props.getSegmentRating.error) return props } }) graphql(DeleteSegmentRating, { props: (props) => ({ deleteSegmentRating: ownProps => props.mutate({ variables: { id: ownProps.id }, optimisticResponse: () => ({ deleteSegmentRating: { ...ownProps, __typename: 'SegmentRating', version: 1 } }) }) }) }) ) export { GetSegmentRating, PostSegmentRating, DeleteSegmentRating, withAppSyncSegmentRating }