UNPKG

graphql-composer

Version:
106 lines 3.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DirectiveDefinition = void 0; const classes_1 = require("../../classes"); const graphql_1 = require("graphql"); const __1 = require("../.."); class DirectiveDefinition extends classes_1.GQLElement { constructor(name) { super(name); this._locations = []; this._args = []; } get args() { return this._args; } get locations() { return this._locations; } get isRepeatable() { return this._isRepeatable; } get definitionNode() { return { kind: "DirectiveDefinition", name: { kind: "Name", value: this.name, }, description: { kind: "StringValue", value: this.description, }, repeatable: this.isRepeatable, locations: this.locations.map((l) => { return { kind: "Name", value: l, }; }), arguments: this._args.map((a) => a.definitionNode), }; } static create(name) { return new DirectiveDefinition(name); } build() { const builtArgs = this._args.reduce((prev, arg) => { const built = arg.build(); prev[built.name] = built; return prev; }, {}); this._built = new graphql_1.GraphQLDirective({ name: this.name, locations: this.locations, description: this.description, args: builtArgs, isRepeatable: this.isRepeatable, extensions: this.extensions, astNode: this.definitionNode, }); return this._built; } setLocations(...locations) { this._locations = locations; return this; } addLocations(...locations) { return this.setLocations(...this.locations, ...locations); } removeLocations(...locations) { locations.map((d) => { const index = this._locations.indexOf(d); this._locations.splice(index, 1); }); return this; } setIsRepeatable(isRepeatable) { this._isRepeatable = isRepeatable; return this; } /* * Set the arguments list of the type * @param args The arguments list */ setArgs(...args) { this._args = args.filter((a) => a); return this; } /** * Add some arguments in the type * @param name The argument name * @param type The argument type */ addArgs(...args) { return this.setArgs(...this.args, ...args); } /** * Remove some arguments in the type * @param args The argument IDs */ removeArgs(...args) { return this.setArgs(...__1.ArrayHelper.remove(args, this._args)); } } exports.DirectiveDefinition = DirectiveDefinition; //# sourceMappingURL=DirectiveDefinition.js.map