import gql from 'graphql-tag' import { graphql, compose } from 'react-apollo' const GetAttribute = gql` query GetAttribute($guid: String, $name: String, $limit: Int, $offset: Int) { getAttribute(guid: $guid, name: $name, limit: $limit, offset: $offset) { } }` const GetAttribute = gql` query GetAttribute($name: String) { getAttribute(name: $name) { guid name description audit } }` const PostAttribute = gql` mutation PostAttribute($attributeForm: AttributeFormInput! ) { postAttribute(attributeForm: $attributeForm) { guid name description audit } }` const DeleteAttribute = gql` mutation DeleteAttribute($name: String) { deleteAttribute(name: $name) { } }` const withAppSyncAttribute = compose( graphql(GetAttribute, { name: 'getAttribute', options: (ownProps) => ({ fetchPolicy: 'cache-and-network', variables: { guid: ownProps.guid, name: ownProps.name, limit: ownProps.limit, offset: ownProps.offset } }), props: (props) => { if (props.getAttribute.error) console.log(props.getAttribute.error) return props } }) graphql(DeleteAttribute, { props: (props) => ({ deleteAttribute: ownProps => props.mutate({ variables: { name: ownProps.name }, optimisticResponse: () => ({ deleteAttribute: { ...ownProps, __typename: 'Attribute', version: 1 } }) }) }) }) ) export { GetAttribute, GetAttribute, PostAttribute, DeleteAttribute, withAppSyncAttribute }