const clearApolloStore = () => { try { client.resetStore(); } catch (e) { console.error('error clearing store'); } }
cache: new InMemoryCache(), }); const healthResponse = await apolloClient.query({ query: gql` query Health {
const { data } = await client.query({ query: SEARCH_USERS, variables: { searchQuery: debounceSearchQuery },
return await client.mutate({ mutation, variables: { input: { ...variables } },
await client.mutate({ mutation: UPDATE_MESSAGE_SEEN, variables: {
async deletePost(activity) { const result = await this.client.mutate({ mutation: gql` mutation { DeletePost(id: "${extractIdFromActivityId(activity.object.id)}") { title } } `, }) throwErrorIfApolloErrorOccurred(result) }
const configureStore = (preloadedState = {}) => { const reducers = combineReducers({ apollo: client.reducer(), form: formReducer, currentUser }); const store = createStore( reducers, preloadedState, applyMiddleware( loggerMiddleware ) ); return { store, client }; }
const getRepositories = ownerLogin => async (dispatch) => { dispatch(loadingRepositories()); client .query({ query: repositoriesQuery, variables: { ownerLogin } }) .then(({ error, data }) => { if (error) { throw new Error(error); } return dispatch(showRepositories(repositoriesFromData(data))); }) .catch(error => dispatch(showRepositoriesError(error))); }
const getProducts = () =>{ return client.query({ fetchPolicy: 'network-only', query: gql` { products{id, name} } ` }) }
const useChatChanged = (channelId, userId) => { const client = useApolloClient(); const published = useSubscription(CHAT_CHANGED, { variables: { channelId } }); const chatChanged = published.data && published.data.chatChanged; if (!chatChanged) return; const cacheData = client.readQuery({ query: GET_CHAT_CACHED }); const data = addOrUpdateChat(userId, cacheData, chatChanged); client.writeQuery({ query: GET_CHAT_CACHED, data }); }
const createProduct = (product) => { return client .mutate({ mutation: MUTATION_QUERY, variables: { product: { ...product, price: parseFloat(product.price)} } }) }
const useGetUserStatus = (isReadOnlyCache) => { const client = useApolloClient(); const readCache = () => { const { authentication } = client.readQuery({ query: GET_USER_STATUS }); return authentication; }; if (isReadOnlyCache) return readCache(); const { data, loading } = useQuery(GET_USER_STATUS); if (loading) return readCache(); return data.authentication; }
const { data } = await client.query({ query: SEARCH_USERS, variables: { searchQuery: debounceSearchQuery },
return await client.mutate({ mutation, variables: { input: { ...variables } },
await client.mutate({ mutation: UPDATE_MESSAGE_SEEN, variables: {