UNPKG

@pothos/core

Version:

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

100 lines (99 loc) 3.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: Object.getOwnPropertyDescriptor(all, name).get }); } _export(exports, { get inputTypeFromParam () { return inputTypeFromParam; }, get typeFromParam () { return typeFromParam; }, get unwrapInputFieldType () { return unwrapInputFieldType; }, get unwrapOutputFieldType () { return unwrapOutputFieldType; } }); const _errors = require("../errors"); const _base = require("../refs/base"); const _inputlist = require("../refs/input-list"); const _list = require("../refs/list"); function unwrapOutputFieldType(type) { if (type.kind === 'List') { return unwrapOutputFieldType(type.type); } return type.ref; } function typeFromParam(param, configStore, nullableOption) { const itemNullable = typeof nullableOption === 'object' ? nullableOption.items : false; const nullable = typeof nullableOption === 'object' ? nullableOption.list : !!nullableOption; if (Array.isArray(param)) { return { kind: 'List', type: typeFromParam(param[0], configStore, itemNullable), nullable }; } if (param instanceof _list.ListRef) { return { kind: 'List', type: typeFromParam(param.listType, configStore, param.nullable), nullable }; } const ref = configStore.getOutputTypeRef(param); const kind = ref instanceof _base.BaseTypeRef ? ref.kind : configStore.getTypeConfig(ref).graphqlKind; const name = ref instanceof _base.BaseTypeRef ? ref.name : configStore.getTypeConfig(ref).name; if (kind !== 'InputObject' && kind !== 'List' && kind !== 'InputList') { return { kind, ref, nullable }; } throw new _errors.PothosSchemaError(`Expected input param ${name} to be an output type but got ${kind}`); } function unwrapInputFieldType(type) { if (type.kind === 'List') { return unwrapInputFieldType(type.type); } return type.ref; } function inputTypeFromParam(param, configStore, requiredOption) { const itemRequired = typeof requiredOption === 'object' ? requiredOption.items : true; const required = typeof requiredOption === 'object' ? requiredOption.list : !!requiredOption; if (Array.isArray(param)) { return { kind: 'List', type: inputTypeFromParam(param[0], configStore, itemRequired), required }; } if (param instanceof _inputlist.InputListRef) { return { kind: 'List', type: inputTypeFromParam(param.listType, configStore, param.required), required }; } const ref = configStore.getInputTypeRef(param); const kind = ref instanceof _base.BaseTypeRef ? ref.kind : configStore.getTypeConfig(ref).graphqlKind; const name = ref instanceof _base.BaseTypeRef ? ref.name : configStore.getTypeConfig(ref).name; if (kind === 'InputObject' || kind === 'Enum' || kind === 'Scalar') { return { kind, ref, required }; } throw new _errors.PothosSchemaError(`Expected input param ${name} to be an InputObject, Enum, or Scalar but got ${kind}`); } //# sourceMappingURL=params.js.map