How to execute an async fetch request and then retry last failed request?

I’m refreshing the token this way (updated OP’s): import { ApolloClient } from ‘apollo-client’; import { onError } from ‘apollo-link-error’; import { ApolloLink, Observable } from ‘apollo-link’; // add Observable // Define Http link const httpLink = new createHttpLink({ uri: ‘/my-graphql-endpoint’, credentials: ‘include’ }); // Add on error handler for apollo link return new ApolloClient({ … Read more

How to chain two GraphQL queries in sequence using Apollo Client

The props added by your firstQuery component will be available to the component below (inside) it, so you can do something like: export default compose( graphql(firstQuery, { name: ‘firstQuery’ }), graphql(secondQuery, { name: ‘secondQuery’, skip: ({ firstQuery }) => !firstQuery.data, options: ({firstQuery}) => ({ variables: { var1: firstQuery.data.someQuery.someValue } }) }) )(withRouter(TestPage)) Notice that we … Read more

How to call useQuery hook conditionally?

React-Apollo: In apollo’s documentation, it shows that there’s a skip option you can add: useQuery(query,{skip:someState===someValue}) Otherwise, you can also useLazyQuery if you want to have a query that you run when you desire it to be run rather than immediately. If you are using the suspense based hooks useSuspenseQuery and useBackgroundQuery you need to use … Read more

How do I handle deletes in react-apollo

I am not sure it is good practise style but here is how I handle the deletion of an item in react-apollo with updateQueries: import { graphql, compose } from ‘react-apollo’; import gql from ‘graphql-tag’; import update from ‘react-addons-update’; import _ from ‘underscore’; const SceneCollectionsQuery = gql ` query SceneCollections { myScenes: selectedScenes (excludeOwner: false, … Read more

How to disable cache in apollo-link or apollo-client?

You can set defaultOptions to your client like this: const defaultOptions: DefaultOptions = { watchQuery: { fetchPolicy: ‘no-cache’, errorPolicy: ‘ignore’, }, query: { fetchPolicy: ‘no-cache’, errorPolicy: ‘all’, }, } const client = new ApolloClient({ link: concat(authMiddleware, httpLink), cache: new InMemoryCache(), defaultOptions: defaultOptions, }); fetchPolicy as no-cache avoids using the cache. See https://www.apollographql.com/docs/react/api/core/ApolloClient/#defaultoptions

React Apollo – Make Multiple Queries

My preferred way is to use the compose functionality of the apollo client (docu). EDIT: If you have more than one query you should name them. So in your case, it could look like this: import React, {Component} from ‘react’ import queries from ‘./queries’ import { graphql, compose } from ‘react-apollo’; class Test extends Component … Read more

tech