import gql from 'graphql-tag' import { graphql, compose } from 'react-apollo' const GetGeneratorService = gql` query GetGeneratorService($guid: String, $uri: String, $generatorKey: String, $limit: Int, $offset: Int) { getGeneratorService(guid: $guid, uri: $uri, generatorKey: $generatorKey, limit: $limit, offset: $offset) { } }` const GetGeneratorService = gql` query GetGeneratorService($guid: String) { getGeneratorService(guid: $guid) { guid uri audit } }` const PostGeneratorService = gql` mutation PostGeneratorService($generatorServiceForm: GeneratorServiceFormInput! ) { postGeneratorService(generatorServiceForm: $generatorServiceForm) { guid uri audit } }` const DeleteGeneratorService = gql` mutation DeleteGeneratorService($guid: String) { deleteGeneratorService(guid: $guid) { } }` const withAppSyncGeneratorService = compose( graphql(GetGeneratorService, { name: 'getGeneratorService', options: (ownProps) => ({ fetchPolicy: 'cache-and-network', variables: { guid: ownProps.guid, uri: ownProps.uri, generatorKey: ownProps.generatorKey, limit: ownProps.limit, offset: ownProps.offset } }), props: (props) => { if (props.getGeneratorService.error) console.log(props.getGeneratorService.error) return props } }) graphql(DeleteGeneratorService, { props: (props) => ({ deleteGeneratorService: ownProps => props.mutate({ variables: { guid: ownProps.guid }, optimisticResponse: () => ({ deleteGeneratorService: { ...ownProps, __typename: 'GeneratorService', version: 1 } }) }) }) }) ) export { GetGeneratorService, GetGeneratorService, PostGeneratorService, DeleteGeneratorService, withAppSyncGeneratorService }