UNPKG

@giraphql/plugin-simple-objects

Version:

A GiraphQL plugin for defining objects and interfaces without ts definitions for those types

74 lines 2.98 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GiraphQLSimpleObjectsPlugin = void 0; require("./global-types"); const core_1 = __importStar(require("@giraphql/core")); const pluginName = 'simpleObjects'; exports.default = pluginName; class GiraphQLSimpleObjectsPlugin extends core_1.BasePlugin { } exports.GiraphQLSimpleObjectsPlugin = GiraphQLSimpleObjectsPlugin; core_1.default.registerPlugin(pluginName, GiraphQLSimpleObjectsPlugin); const proto = core_1.default.prototype; proto.simpleObject = function simpleObject(name, options) { const ref = new core_1.ObjectRef(name); if (options.fields) { const originalFields = options.fields; // eslint-disable-next-line no-param-reassign options.fields = (t) => { const fields = originalFields(t); Object.keys(fields).forEach((key) => { this.configStore.onFieldUse(fields[key], (config) => { if (config.kind === 'Object') { // eslint-disable-next-line no-param-reassign config.resolve = (parent) => parent[key]; } }); }); return fields; }; } this.objectType(ref, options); return ref; }; proto.simpleInterface = function simpleInterface(name, options) { const ref = new core_1.InterfaceRef(name); if (options.fields) { const originalFields = options.fields; // eslint-disable-next-line no-param-reassign options.fields = (t) => { const fields = originalFields(t); Object.keys(fields).forEach((key) => { this.configStore.onFieldUse(fields[key], (config) => { if (config.kind === 'Interface') { // eslint-disable-next-line no-param-reassign config.resolve = (parent) => parent[key]; } }); }); return fields; }; } this.interfaceType(ref, options); return ref; }; //# sourceMappingURL=index.js.map