graphql-validation-complexity icon indicating copy to clipboard operation
graphql-validation-complexity copied to clipboard

Change the cost of __typename

Open emileber opened this issue 6 years ago • 2 comments

We'd need to adjust the cost of __typename for every type. Is there a quick way?

emileber avatar Sep 11 '19 16:09 emileber

Hmm, I don't see a way to adjust the cost of __typename in the current API, actually. Do you have an idea for how this sort of API should look?

taion avatar Sep 11 '19 16:09 taion

Maybe generic getCost and getCostFactor in the options object, which receives the field name or type. Not sure what's best.

const ComplexityLimitRule = createComplexityLimitRule(1000, {
  scalarCost: 1,
  
  // Maybe something like this:
  getCost: (cost, field) => field === '__typename' ? MY_CUSTOM_COST : cost,
});

emileber avatar Sep 11 '19 16:09 emileber