Gradually enabling Stellate

Sometimes, you might want to send certain operations from the client via Stellate and others to the origin directly. (for example, to run an A/B test) You can do this by switching the URL your GraphQL Client sends requests to depending on the operation.

Apollo Client

With Apollo Client, you can pass a function to the HTTP Link's uri configuration option that takes in the operation and can return any URI to send the request to. The simplest way to send certain operations to Stellate is to check the input.operationName:

const client = new ApolloClient({
  uri: (operation) => {
    // Send the getRockets query via Stellate
    if (operation.operationName === 'getRockets') {
      return ''

    // All other operations go directly to the origin
    return ''
  // …more options here…

You could also go through the parsed operation in input.operation in case you want to e.g. only send requests with certain types or fields to Stellate.