How to use the graphql-query-complexity/dist/QueryComplexity function in graphql-query-complexity

To help you get started, we’ve selected a few graphql-query-complexity examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MichalLytek / type-graphql / tests / functional / resolvers.ts View on Github external
function generateAndVisitComplexMethod(maximumComplexity: number): ValidationContext {
      const query = /* graphql */ `
        query {
          sampleQuery {
            complexResolverMethod
          }
        }
      `;
      const ast = parse(query);
      const typeInfo = new TypeInfo(schema);
      const context = new ValidationContext(schema, ast, typeInfo);
      const visitor = new ComplexityVisitor(context, {
        maximumComplexity,
        estimators: [fieldExtensionsEstimator(), simpleEstimator({ defaultComplexity: 1 })],
      });
      visit(ast, visitWithTypeInfo(typeInfo, visitor));
      return context;
    }

graphql-query-complexity

Validation rule for GraphQL query complexity analysis

MIT
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis