Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: return `0` complexity for introspection fields (#4549)

Mir Arif Hasanc9fb5bf45cd2
diff --git a/packages/hoppscotch-backend/src/plugins/GQLComplexityPlugin.ts b/packages/hoppscotch-backend/src/plugins/GQLComplexityPlugin.ts
index 52b894557..31655facf 100644
--- a/packages/hoppscotch-backend/src/plugins/GQLComplexityPlugin.ts
+++ b/packages/hoppscotch-backend/src/plugins/GQLComplexityPlugin.ts
@@ -7,6 +7,7 @@ import {
import { Plugin } from '@nestjs/apollo';
import { GraphQLError } from 'graphql';
import {
+ ComplexityEstimatorArgs,
fieldExtensionsEstimator,
getComplexity,
simpleEstimator,
@@ -29,6 +30,14 @@ export class GQLComplexityPlugin implements ApolloServerPlugin {
query: document,
variables: request.variables,
estimators: [
+ // Custom estimator for introspection fields
+ (args: ComplexityEstimatorArgs) => {
+ const fieldName = args.field.name;
+ if (fieldName.startsWith('__')) {
+ return 0; // Return 0 complexity for introspection fields
+ }
+ return;
+ },
fieldExtensionsEstimator(),
simpleEstimator({ defaultComplexity: 1 }),
],