import gql from 'graphql-tag' import { graphql, compose } from 'react-apollo' const GetUser = gql` query GetUser($guid: String, $email: String, $token: String) { getUser(guid: $guid, email: $email, token: $token) { } }` const GetUser = gql` query GetUser($guid: String) { getUser(guid: $guid) { guid email nickname name audit } }` const PostUser = gql` mutation PostUser($email: String, $password: String) { postUser(email: $email, password: $password) { user { guid email nickname name audit } session { id expires_at } } }` const PostUser = gql` mutation PostUser($token: String) { postUser(token: $token) { user { guid email nickname name audit } session { id expires_at } } }` const PostUser = gql` mutation PostUser($userForm: UserFormInput! ) { postUser(userForm: $userForm) { guid email nickname name audit } }` const PutUser = gql` mutation PutUser($userUpdateForm: UserUpdateFormInput! , $guid: String) { putUser(userUpdateForm: $userUpdateForm, guid: $guid) { guid email nickname name audit } }` const withAppSyncUser = compose( graphql(GetUser, { name: 'getUser', options: (ownProps) => ({ fetchPolicy: 'cache-and-network', variables: { guid: ownProps.guid, email: ownProps.email, token: ownProps.token } }), props: (props) => { if (props.getUser.error) console.log(props.getUser.error) return props } }), graphql(PutUser, { props: (props) => ({ putUser: ownProps => props.mutate({ variables: { userUpdateForm: ownProps.userUpdateForm, guid: ownProps.guid }, optimisticResponse: () => ({ putUser: { ...ownProps.user, __typename: 'User', version: 1 } }) }) }) }) ) export { GetUser, GetUser, PostUser, PostUser, PostUser, PutUser, withAppSyncUser }