import gql from 'graphql-tag' import { graphql, compose } from 'react-apollo' const GetVersion = gql` query GetVersion($orgKey: String, $applicationKey: String, $limit: Int, $offset: Int) { getVersion(orgKey: $orgKey, applicationKey: $applicationKey, limit: $limit, offset: $offset) { } }` const GetVersion = gql` query GetVersion($orgKey: String, $applicationKey: String, $version: String) { getVersion(orgKey: $orgKey, applicationKey: $applicationKey, version: $version) { guid organization application version original { type data } service audit } }` const PostVersion = gql` mutation PostVersion($versionForm: VersionFormInput! , $orgKey: String, $version: String) { postVersion(versionForm: $versionForm, orgKey: $orgKey, version: $version) { guid organization application version original { type data } service audit } }` const PutVersion = gql` mutation PutVersion($versionForm: VersionFormInput! , $orgKey: String, $applicationKey: String, $version: String) { putVersion(versionForm: $versionForm, orgKey: $orgKey, applicationKey: $applicationKey, version: $version) { guid organization application version original { type data } service audit } }` const DeleteVersion = gql` mutation DeleteVersion($orgKey: String, $applicationKey: String, $version: String) { deleteVersion(orgKey: $orgKey, applicationKey: $applicationKey, version: $version) { } }` const GetVersion = gql` query GetVersion($orgKey: String, $applicationKey: String, $version: String, $typeName: String, $subTypeName: String, $optionalFields: Boolean) { getVersion(orgKey: $orgKey, applicationKey: $applicationKey, version: $version, typeName: $typeName, subTypeName: $subTypeName, optionalFields: $optionalFields) { } }` const withAppSyncVersion = compose( graphql(GetVersion, { name: 'getVersion', options: (ownProps) => ({ fetchPolicy: 'cache-and-network', variables: { orgKey: ownProps.orgKey, applicationKey: ownProps.applicationKey, limit: ownProps.limit, offset: ownProps.offset } }), props: (props) => { if (props.getVersion.error) console.log(props.getVersion.error) return props } }), graphql(PutVersion, { props: (props) => ({ putVersion: ownProps => props.mutate({ variables: { versionForm: ownProps.versionForm, orgKey: ownProps.orgKey, applicationKey: ownProps.applicationKey, version: ownProps.version }, optimisticResponse: () => ({ putVersion: { ...ownProps.version, __typename: 'Version', version: 1 } }) }) }) }), graphql(DeleteVersion, { props: (props) => ({ deleteVersion: ownProps => props.mutate({ variables: { orgKey: ownProps.orgKey, applicationKey: ownProps.applicationKey, version: ownProps.version }, optimisticResponse: () => ({ deleteVersion: { ...ownProps, __typename: 'Version', version: 1 } }) }) }) }) ) export { GetVersion, GetVersion, PostVersion, PutVersion, DeleteVersion, GetVersion, withAppSyncVersion }