Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Let the user of apollo-link-batch-http decide which request to batch #394

Closed
eskimoblood opened this issue Jan 7, 2018 · 2 comments
Closed

Comments

@eskimoblood
Copy link

When using apollo-link-batch-http all request in a specific time interval are called in batch. In our application most of the request are fast but we also we have some time consuming requests. Batching known slow request with other would result in a poorer user experience, as now all request have the same response time as the slowest one. That's why it would be nice if there would be a callback that can decide if a request should be batch ar fired immediately.

@charleyw
Copy link

charleyw commented Jan 25, 2018

You can do it with split
links.js

const batchHttpLink = new BatchHttpLink({
  fetch: createApolloFetch({
    constructOptions,
    uri: process.env.REACT_APP_API_ENDPOINT,
  }),
})

const normalHttpLink = createHttpLink({
  uri: '/graphql',
  credentials: 'same-origin',
})

export split(({getContext}) => getContext().noBatch, normalHttpLink, batchHttpLink)

Make a query not use batch link

const ProfileWithData = graphql(CurrentUserForLayout, {
  options: { 
    context: { noBatch: true }
  },
})(Profile);

Here I use noBatch in context to control whether a query should be batched. By default all queries will be batched.

@Poincare
Copy link
Contributor

Thank you for the example @charleyw - I will go ahead and close this since the question seems to have been answered.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants