import gql from 'graphql-tag' import { graphql, compose } from 'react-apollo' const GetCustomer = gql` query GetCustomer($financialAccountNumber: String, $email: String, $customerName: String) { getCustomer(financialAccountNumber: $financialAccountNumber, email: $email, customerName: $customerName) { } }` const GetCustomer = gql` query GetCustomer($customerName: String) { getCustomer(customerName: $customerName) { financialAccountNumber customerName branchNumber address1 address2 city state zip } }` const PostCustomer = gql` mutation PostCustomer($customerCreateForm: CustomerCreateFormInput! ) { postCustomer(customerCreateForm: $customerCreateForm) { financialAccountNumber customerName branchNumber address1 address2 city state zip } }` const PutCustomer = gql` mutation PutCustomer($customerUpdateForm: CustomerUpdateFormInput! , $customerName: String) { putCustomer(customerUpdateForm: $customerUpdateForm, customerName: $customerName) { financialAccountNumber customerName branchNumber address1 address2 city state zip } }` const withAppSyncCustomer = compose( graphql(GetCustomer, { name: 'getCustomer', options: (ownProps) => ({ fetchPolicy: 'cache-and-network', variables: { financialAccountNumber: ownProps.financialAccountNumber, email: ownProps.email, customerName: ownProps.customerName } }), props: (props) => { if (props.getCustomer.error) console.log(props.getCustomer.error) return props } }), graphql(PutCustomer, { props: (props) => ({ putCustomer: ownProps => props.mutate({ variables: { customerUpdateForm: ownProps.customerUpdateForm, customerName: ownProps.customerName }, optimisticResponse: () => ({ putCustomer: { ...ownProps.customer, __typename: 'Customer', version: 1 } }) }) }) }) ) export { GetCustomer, GetCustomer, PostCustomer, PutCustomer, withAppSyncCustomer }