Can we modify the quota limit based on graphql query complexity?

We would like to to update the quota limit for any key, based on the what type of queries are made using the auth key, is there a way to achieve it and and how can it be done?

Hey @Himanshu_Bisht and welcome to Tyk community!

Based on the title of your question I am assuming you want to probably:

  1. allow more quota to users that send simple queries, with query depth of 2 or 3
  2. allow less quota to users that send complicated queries with 10 for example

You could do that by creating different policies first and then issuing keys based on those policies. For example for policy with the small query depth you could set the following parameters:

{ 
  "rate": 1000,
  "per": 60,
  "max_query_depth": 3
}

While for the complicated queries:

{ 
  "rate": 200,
  "per": 60,
  "max_query_depth": 10
}

(setting max_query_depth to -1 will result in unlimited complexity being allowed).

Then if you start issuing keys based on those policies they will each inherit the quotas. If you have a need to change the quotas at any time, you just edit the policy and all the keys issued based off of it immediately start enforcing the new quota.

Here’s a link to our docs on how to do it in in the GUI: Secure an API
Or using Tyk Gateway API if you’re working with the open-source gateway: Secure an API

And we have Postman collections to make it easier as well: Postman

Hope it helps!

I want to attach both these policies to single key, can you share how we can do this.

This isn’t possible with the same API definition. They would either have to be different APIs or different versions of the same API.

In summary, it isn’t possible for you to have the same key dynamical choose a quota or rate limit based on the query depth. They have to be different keys.

Hope this helps.