Hi,
I am trying to find out if there is a way to disable batch mutations from resolving or working in a single request.
The test I am doing is sending via Postman a batch request of mutations with the same operationName but same values or different values.
My data is sent as an array of JSON objects. I simply copy/pasted an example from my browser.
In both cases, they are all resolving, this causes me an issue when trying to apply rate limiting.
Is there a way to disable this feature for mutations only?
Any help or advice is appreciated.
Thanks!
Hello! Yes, you can use the split
method of ApolloLink
to send some operations (i.e., your queries) with BatchHttpLink
, and other operations (i.e., your mutations) with the standard HttpLink
.
Please see this question.
Hi, thanks for your reply.
The test I am running is with Postman, an API test tool.
So I am not sending my request using the apollo-client at all.
I am wondering about this on apollo-server side specifically not on the client side.
Sorry if I was not being clear.
Apologies for the confusion! To further clarify your use case, are you saying that you’d like to configure Apollo Server such that whenever it receives a batched request with multiple operations, that it does not process any mutations included in that batch?
If so, this sounds like it might be risky if any of your production clients end up sending batched requests as well. I might recommend instead setting a custom header within your Postman requests that Apollo Server can check for and add to the context, as shown in Authentication and authorization.
Your mutation resolvers could then check for the presence of this header and bail out by returning null
or a dummy object.
Yes, that is what I am trying to do.
I recently integrated this library to limit the rate of requests from an authenticated user.
It allows me to specify a limit of requests for a mutation at an interval and it works great for that.
But the problem I am having, is during my testing, I noticed that if I send a batched request, it treats every batched mutation, as a single request.
I believe this issue is because apollo-server treats and run a batch request in parallel.
I posted an issue on the git repo for their advice, but was hoping to see if there were any other ideas or advices here for this.