UNPKG

gqlcheck

Version:

Performs additional checks on your GraphQL documents and operations to ensure they conform to your rules, whilst allow-listing existing operations and their constituent parts (and allowing overrides on a per-field basis). Rules include max selection set d

26 lines (25 loc) 702 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CountVisitor = CountVisitor; const graphql_1 = require("graphql"); let counts = {}; function CountVisitor(context) { return { enter(node) { if (node.kind === graphql_1.Kind.DOCUMENT) { counts = Object.create(null); } if (counts[node.kind] === undefined) { counts[node.kind] = 1; } else { counts[node.kind]++; } }, leave(node) { if (node.kind === graphql_1.Kind.DOCUMENT) { context.addMeta("count", counts); } }, }; }