Sending apollo request outside batch

Viewed 346

I have an apollo frontend with batch requests set up. However there are certain requests that shouldn't be included in the batch:

  • A component depends on a "small" version of a request to load
  • The "full" request should happen at the same time, to be entered into the cache for later use
  • If the small and full request are sent in the same batch it doesn't return until the full one is finished, which takes too long.

I've thought of two non-ideal solutions:

  • Start the full request once the small one is finished, using onCompleted. Not ideal because for speed I'd like to start the two simultaneously
  • Set up two backend endpoints, one with batching and one without, and use split to direct requests where appropriate. Would work but I'd like to get away without an extra endpoint

Any ideas?

EDIT: I've realised that the first solution is no good because it can cause other unrelated queries to be delayed - so the only option so far is the last solution.

1 Answers

I am not an expert on the topic but it seems that batchKey option in apllo-link-batch-http is what you are looking for. The easiest would be to for example prefix your operations with a keyword:

const link = BatchHttpLink({
  batchKey: operation =>
    operation.name && operation.name.value.startsWith('eager_') ? 'eager' : 'normal'
});
Related