import gql from 'graphql-tag' import { graphql, compose } from 'react-apollo' const PostPayment = gql` mutation PostPayment($payid: Int, $paymentMethod: String, $actorid: String, $refAccountid: Int, $operatorid: String, $amount: Float, $currency: String, $phone: Int, $pin: Int, $paymentContext: String) { postPayment(payid: $payid, paymentMethod: $paymentMethod, actorid: $actorid, refAccountid: $refAccountid, operatorid: $operatorid, amount: $amount, currency: $currency, phone: $phone, pin: $pin, paymentContext: $paymentContext) { payid actorid amount ref_accountid payment_method operatorid phone pin currency payment_context } }` const PutPayment = gql` mutation PutPayment($payid: Int, $paymentMethod: String, $actorid: String, $refAccountid: Int, $operatorid: String, $amount: Float, $phone: Int, $pin: Int, $currency: String, $paymentContext: String) { putPayment(payid: $payid, paymentMethod: $paymentMethod, actorid: $actorid, refAccountid: $refAccountid, operatorid: $operatorid, amount: $amount, phone: $phone, pin: $pin, currency: $currency, paymentContext: $paymentContext) { payid actorid amount ref_accountid payment_method operatorid phone pin currency payment_context } }` const DeletePayment = gql` mutation DeletePayment($payid: Int) { deletePayment(payid: $payid) { } }` const GetPayment = gql` query GetPayment($payid: Int, $paymentMethod: String, $actorid: String, $refAccountid: Int, $operatorid: String, $amount: Float, $phone: Int, $pin: Int, $currency: String, $paymentContext: String) { getPayment(payid: $payid, paymentMethod: $paymentMethod, actorid: $actorid, refAccountid: $refAccountid, operatorid: $operatorid, amount: $amount, phone: $phone, pin: $pin, currency: $currency, paymentContext: $paymentContext) { payid actorid amount ref_accountid payment_method operatorid phone pin currency payment_context } }` const GetPayment = gql` query GetPayment($refAccountid: Int, $payid: Int, $paymentMethod: String, $actorid: String, $operatorid: String, $amount: Float, $phone: Int, $pin: Int, $currency: String, $paymentContext: String) { getPayment(refAccountid: $refAccountid, payid: $payid, paymentMethod: $paymentMethod, actorid: $actorid, operatorid: $operatorid, amount: $amount, phone: $phone, pin: $pin, currency: $currency, paymentContext: $paymentContext) { payid actorid amount ref_accountid payment_method operatorid phone pin currency payment_context } }` const GetPayment = gql` query GetPayment($payid: Int, $paymentMethod: String, $actorid: String, $refAccountid: Int, $operatorid: String, $amount: Float, $phone: Int, $pin: Int, $currency: String, $paymentContext: String) { getPayment(payid: $payid, paymentMethod: $paymentMethod, actorid: $actorid, refAccountid: $refAccountid, operatorid: $operatorid, amount: $amount, phone: $phone, pin: $pin, currency: $currency, paymentContext: $paymentContext) { } }` const withAppSyncPayment = compose( graphql(GetPayment, { name: 'getPayment', options: (ownProps) => ({ fetchPolicy: 'cache-and-network', variables: { payid: ownProps.payid, paymentMethod: ownProps.paymentMethod, actorid: ownProps.actorid, refAccountid: ownProps.refAccountid, operatorid: ownProps.operatorid, amount: ownProps.amount, phone: ownProps.phone, pin: ownProps.pin, currency: ownProps.currency, paymentContext: ownProps.paymentContext } }), props: (props) => { if (props.getPayment.error) console.log(props.getPayment.error) return props } }), graphql(PutPayment, { props: (props) => ({ putPayment: ownProps => props.mutate({ variables: { payid: ownProps.payid, paymentMethod: ownProps.paymentMethod, actorid: ownProps.actorid, refAccountid: ownProps.refAccountid, operatorid: ownProps.operatorid, amount: ownProps.amount, phone: ownProps.phone, pin: ownProps.pin, currency: ownProps.currency, paymentContext: ownProps.paymentContext }, optimisticResponse: () => ({ putPayment: { ...ownProps.payment, __typename: 'Payment', version: 1 } }) }) }) }), graphql(DeletePayment, { props: (props) => ({ deletePayment: ownProps => props.mutate({ variables: { payid: ownProps.payid }, optimisticResponse: () => ({ deletePayment: { ...ownProps, __typename: 'Payment', version: 1 } }) }) }) }) ) export { PostPayment, PutPayment, DeletePayment, GetPayment, GetPayment, GetPayment, withAppSyncPayment }