graphql: Instrument field count and depth
Created by: ryanslade
This is v2 of our cost estimator, it's still a WIP and the idea is to deploy this in production so that we can get a sample of real world costs using this algorithm in Honeycomb.
This version tries to count the worst case number of fields returned by a query and treats all fields as having a cost of 1.
Additionally, it finds first
and last
parameters and uses them to multiply cost. For example, in the
following query we always assume that 10 externalServices
nodes will be returned and we therefore expect
10 occurences of displayName
and webhookURL
in the result:
query{
externalServices(first: 10){
nodes{
displayName
webhookURL
}
}
somethingElse
}
When the estimator encounters inline fragments it evaluates the cost of each and pick the most expensive as we want the worst case.