I have a case where I need to make the same graphql query multiple times, with the same variables, but with a different authorization token for each request. I am setting the token in the context options of the actual query
However only one of the query requests I generate is actually sent, the rest are fulfilled with the response data of the first request. I realize this must have something to do with the caching - I’ve tried setting fetchPolicy to 'no-cache', and the resultCaching: false in the cache/InMemoryCache options, but still getting the same behaviour.
Was hoping someone could point me in the right direction?
What you’re seeing is query deduplication at work. Query deduplication is enabled by default and will only issue a single query if an existing query is in flight with the same query string, operation name, and variables. You can choose to disable this 1 of 2 ways:
Globally disable query deduplication in the ApolloClient constructor.
const client = new ApolloClient({
queryDeduplication: false
})
Disable it on a per query basis. You can do this with context.queryDeduplication if you’d like to leave this behavior on by default, but turn it off for select queries.