Apollo Link always-on?

Hey everyone, first post here so please be nice :slight_smile:

I’m looking in to setting up apollo-link so that I can batch my Dashboard queries instead of having 5-10 component all making their own queries.

If I setup/enable batching via apollo-link will all queries throughout my app default to batching? For example I load up Page C and on that page it queries for data it needs, but there is also a UserProfile component that queries for the user name/fullname etc. Would those queries be batched?

I haven’t found anything in the documentation in terms of enabling/disabling batching for specific queries/components. Any help or insight would be awesome.

Hello and welcome! If you want to batch some of your operations with BatchHttpLink and send others immediately with a regular HttpLink, you can branch your link chain’s execution with the split method of ApolloLink.

Here’s a basic split where you could set an isBatched boolean to true in the context option for each operation that you do want to batch:

const splitLink = new ApolloLink().split(
  (operation) => operation.getContext().isBatched,
  new BatchHttpLink({
    uri: "http://localhost:4000/graphql"
  new HttpLink({
    uri: "http://localhost:4000/graphql"
1 Like

@StephenBarlow That should work, thank you!

1 Like