UNPKG

@pothos/core

Version:

Pothos (formerly GiraphQL) is a plugin based schema builder for creating code-first GraphQL schemas in typescript

143 lines (142 loc) 5.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "FieldBuilder", { enumerable: true, get: function() { return FieldBuilder; } }); const _root = require("./root"); class FieldBuilder extends _root.RootFieldBuilder { /** * Create a Boolean field from a boolean property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeBoolean(name, ...args) { const [options = {}] = args; return this.exposeField(name, { ...options, type: 'Boolean' }); } /** * Create a Float field from a numeric property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeFloat(name, ...args) { const [options = {}] = args; return this.exposeField(name, { ...options, type: 'Float' }); } /** * Create an ID field from a property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeID(name, ...args) { const [options = {}] = args; return this.exposeField(name, { ...options, type: 'ID' }); } /** * Create an Int field from a numeric property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeInt(name, ...args) { const [options = {}] = args; return this.exposeField(name, { ...options, type: 'Int' }); } /** * Create a String field from a string property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeString(name, ...args) { const [options = {}] = args; return this.exposeField(name, { ...options, type: 'String' }); } /** * Create a Boolean list field from a boolean[] property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeBooleanList(name, ...args) { const [options = {}] = args; return this.exposeField(name, { ...options, type: [ 'Boolean' ] }); } /** * Create a Float list field from a number[] property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeFloatList(name, ...args) { const [options = {}] = args; return this.exposeField(name, { ...options, type: [ 'Float' ] }); } /** * Create an ID list field from an id[] property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeIDList(name, ...args) { const [options = {}] = args; return this.exposeField(name, { ...options, type: [ 'ID' ] }); } /** * Create a Int list field from a number[] property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeIntList(name, ...args) { const [options = {}] = args; return this.exposeField(name, { ...options, type: [ 'Int' ] }); } /** * Create a String list field from a string[] property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeStringList(name, ...args) { const [options = {}] = args; return this.exposeField(name, { ...options, type: [ 'String' ] }); } /** * Create a field that resolves to a property of the corresponding type on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ expose(name, ...args) { const [options = {}] = args; return this.exposeField(name, options); } } //# sourceMappingURL=builder.js.map