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

36 lines (35 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RuleError = void 0; const graphql_1 = require("graphql"); const graphqlMajor = parseInt(graphql_1.version.split(".")[0], 10); class RuleError extends graphql_1.GraphQLError { options; constructor(message, options) { if (graphqlMajor < 16) { const { nodes, source, positions, path, originalError, extensions } = options; // message, nodes, source, positions, path, originalError, extensions super(message, nodes, source, positions, path, originalError, extensions); } else { super(message, options); } try { this.name = "RuleError"; } catch (e) { // Ignore error on GraphQL v15 } Object.defineProperty(this, "options", { value: options }); } toJSONEnhanced(context) { return { ...(super.toJSON?.() ?? (0, graphql_1.formatError)(this)), infraction: this.options.infraction, operations: this.options.errorOperationLocations ?? context.getErrorOperationLocationsForNodes(this.nodes), override: this.options.override, }; } } exports.RuleError = RuleError;