import gql from 'graphql-tag' import { graphql, compose } from 'react-apollo' const GetWatch = gql` query GetWatch($guid: String, $userGuid: String, $organizationKey: String, $applicationKey: String, $limit: Int, $offset: Int) { getWatch(guid: $guid, userGuid: $userGuid, organizationKey: $organizationKey, applicationKey: $applicationKey, limit: $limit, offset: $offset) { } }` const GetWatch = gql` query GetWatch($guid: String) { getWatch(guid: $guid) { guid user { guid email nickname name audit } organization { guid key name namespace visibility domains { name } audit } application { guid organization name key visibility description audit } audit } }` const GetWatch = gql` query GetWatch($userGuid: String, $organizationKey: String, $applicationKey: String) { getWatch(userGuid: $userGuid, organizationKey: $organizationKey, applicationKey: $applicationKey) { } }` const PostWatch = gql` mutation PostWatch($watchForm: WatchFormInput! ) { postWatch(watchForm: $watchForm) { guid user { guid email nickname name audit } organization { guid key name namespace visibility domains { name } audit } application { guid organization name key visibility description audit } audit } }` const DeleteWatch = gql` mutation DeleteWatch($guid: String) { deleteWatch(guid: $guid) { } }` const withAppSyncWatch = compose( graphql(GetWatch, { name: 'getWatch', options: (ownProps) => ({ fetchPolicy: 'cache-and-network', variables: { guid: ownProps.guid, userGuid: ownProps.userGuid, organizationKey: ownProps.organizationKey, applicationKey: ownProps.applicationKey, limit: ownProps.limit, offset: ownProps.offset } }), props: (props) => { if (props.getWatch.error) console.log(props.getWatch.error) return props } }) graphql(DeleteWatch, { props: (props) => ({ deleteWatch: ownProps => props.mutate({ variables: { guid: ownProps.guid }, optimisticResponse: () => ({ deleteWatch: { ...ownProps, __typename: 'Watch', version: 1 } }) }) }) }) ) export { GetWatch, GetWatch, GetWatch, PostWatch, DeleteWatch, withAppSyncWatch }