graphql-composer
Version:
Create your GraphQL API using composition!
72 lines • 2.26 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.InputField = void 0;
const __1 = require("../..");
const GQLField_1 = require("./GQLField");
class InputField extends GQLField_1.GQLField {
constructor(name, type) {
super(name, type);
}
get type() {
return this._type;
}
get definitionNode() {
return {
name: {
kind: "Name",
value: this.name,
},
kind: "InputValueDefinition",
description: {
kind: "StringValue",
value: this.description,
},
type: {
kind: "NamedType",
name: {
kind: "Name",
value: __1.TypeParser.parse(this.type).toString(),
},
},
directives: this.directives.map((d) => d.definitionNode),
};
}
static create(nameOrField, type) {
if (typeof nameOrField === "string") {
return new InputField(nameOrField, type);
}
else if (nameOrField instanceof GQLField_1.GQLField) {
const field = InputField.create(nameOrField.name, nameOrField.type)
.setDescription(nameOrField.description)
.setExtensions(nameOrField.extensions)
.setDirectives(...nameOrField.directives)
.setDeprecationReason(nameOrField.deprecationReason);
return field;
}
}
build() {
const input = {
name: this._name,
type: __1.TypeParser.parse(this._type, __1.Schema.config.requiredByDefault, __1.Schema.config.arrayRequired),
description: this._description,
defaultValue: this._defaultValue,
astNode: undefined,
extensions: this.extensions,
};
this._built = input;
return this.built;
}
copy() {
return InputField.create(this);
}
convert(to) {
if (to === __1.Arg) {
return to.create(this);
}
else if (to === __1.Field) {
return to.create(this);
}
}
}
exports.InputField = InputField;
//# sourceMappingURL=InputField.js.map
;