import gql from 'graphql-tag' import { graphql, compose } from 'react-apollo' const GetView = gql` query GetView($offset: Int, $limit: Int, $sortBy: String, $direction: ) { getView(offset: $offset, limit: $limit, sortBy: $sortBy, direction: $direction) { page data { guid name projection variables } } }` const GetView = gql` query GetView($guid: String) { getView(guid: $guid) { guid name projection variables } }` const PostView = gql` mutation PostView($viewForm: ViewFormInput! ) { postView(viewForm: $viewForm) { guid name projection variables } }` const PutView = gql` mutation PutView($viewForm: ViewFormInput! , $guid: String) { putView(viewForm: $viewForm, guid: $guid) { guid name projection variables } }` const DeleteView = gql` mutation DeleteView($guid: String) { deleteView(guid: $guid) { } }` const withAppSyncView = compose( graphql(GetView, { name: 'getView', options: (ownProps) => ({ fetchPolicy: 'cache-and-network', variables: { offset: ownProps.offset, limit: ownProps.limit, sortBy: ownProps.sortBy, direction: ownProps.direction } }), props: (props) => { if (props.getView.error) console.log(props.getView.error) return props } }), graphql(PutView, { props: (props) => ({ putView: ownProps => props.mutate({ variables: { viewForm: ownProps.viewForm, guid: ownProps.guid }, optimisticResponse: () => ({ putView: { ...ownProps.view, __typename: 'View', version: 1 } }) }) }) }), graphql(DeleteView, { props: (props) => ({ deleteView: ownProps => props.mutate({ variables: { guid: ownProps.guid }, optimisticResponse: () => ({ deleteView: { ...ownProps, __typename: 'View', version: 1 } }) }) }) }) ) export { GetView, GetView, PostView, PutView, DeleteView, withAppSyncView }