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.
Only sending certain operations via Stellate might have unintended side effects.
For example, Automatic Mutation Invalidation might not work as expected because certain mutations aren't passed through Stellate and adding types or fields to your caching rules might not enable caching because the queries you're trying to target aren't passed through Stellate.
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 'https://spacex-api.stellate.sh'
}
// All other operations go directly to the origin
return 'https://api.spacex.land/graphql/'
},
// …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.