import gql from 'graphql-tag' import { graphql, compose } from 'react-apollo' const PostAccount = gql` mutation PostAccount($accountForm: AccountFormInput! , $authorization: String, $test: Boolean, $testDefault: Boolean) { postAccount(accountForm: $accountForm, authorization: $authorization, test: $test, testDefault: $testDefault) { id awsAccount name enabled } }` const GetAccount = gql` query GetAccount($id: String, $authorization: String) { getAccount(id: $id, authorization: $authorization) { id awsAccount name enabled } }` const GetAccount = gql` query GetAccount($id: String, $authorization: String, $name: String, $page: Int, $count: Int) { getAccount(id: $id, authorization: $authorization, name: $name, page: $page, count: $count) { } }` const GetAccount = gql` query GetAccount($authorization: String, $name: String, $page: Int, $count: Int) { getAccount(authorization: $authorization, name: $name, page: $page, count: $count) { } }` const DeleteAccount = gql` mutation DeleteAccount($id: String, $authorization: String) { deleteAccount(id: $id, authorization: $authorization) { id awsAccount name enabled } }` const withAppSyncAccount = compose( graphql(GetAccount, { name: 'getAccount', options: (ownProps) => ({ fetchPolicy: 'cache-and-network', variables: { id: ownProps.id, authorization: ownProps.authorization } }), props: (props) => { if (props.getAccount.error) console.log(props.getAccount.error) return props } }) graphql(DeleteAccount, { props: (props) => ({ deleteAccount: ownProps => props.mutate({ variables: { id: ownProps.id, authorization: ownProps.authorization }, optimisticResponse: () => ({ deleteAccount: { ...ownProps, __typename: 'Account', version: 1 } }) }) }) }) ) export { PostAccount, GetAccount, GetAccount, GetAccount, DeleteAccount, withAppSyncAccount }