UNPKG

graphile-settings

Version:
44 lines (43 loc) 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveTableType = resolveTableType; exports.buildInflectionMeta = buildInflectionMeta; exports.buildQueryMeta = buildQueryMeta; const inflection_utils_1 = require("./inflection-utils"); function resolveTableType(build, codec) { return (0, inflection_utils_1.safeInflection)(() => build.inflection.tableType(codec), (0, inflection_utils_1.fallbackTableType)(codec.name)); } function buildInflectionMeta(resource, tableType, build) { const inflection = build.inflection; return { tableType, allRows: (0, inflection_utils_1.safeInflection)(() => inflection.allRows?.(resource), `${tableType.toLowerCase()}s`), connection: (0, inflection_utils_1.safeInflection)(() => inflection.connectionType?.(tableType), `${tableType}Connection`), edge: (0, inflection_utils_1.safeInflection)(() => inflection.edgeType?.(tableType), `${tableType}Edge`), filterType: (0, inflection_utils_1.safeInflection)(() => inflection.filterType?.(tableType), `${tableType}Filter`), orderByType: (0, inflection_utils_1.safeInflection)(() => inflection.orderByType?.(tableType), `${tableType}OrderBy`), conditionType: (0, inflection_utils_1.safeInflection)(() => inflection.conditionType?.(tableType), `${tableType}Condition`), patchType: (0, inflection_utils_1.safeInflection)(() => inflection.patchType?.(tableType), `${tableType}Patch`), createInputType: (0, inflection_utils_1.safeInflection)(() => inflection.createInputType?.(resource), `Create${tableType}Input`), createPayloadType: (0, inflection_utils_1.safeInflection)(() => inflection.createPayloadType?.(resource), `Create${tableType}Payload`), updatePayloadType: (0, inflection_utils_1.safeInflection)(() => inflection.updatePayloadType?.(resource), `Update${tableType}Payload`), deletePayloadType: (0, inflection_utils_1.safeInflection)(() => inflection.deletePayloadType?.(resource), `Delete${tableType}Payload`), }; } function buildQueryMeta(resource, uniques, tableType, build) { const inflection = build.inflection; const hasPrimaryKey = uniques.some((unique) => unique.isPrimary); return { all: (0, inflection_utils_1.safeInflection)(() => inflection.allRows?.(resource), `${tableType.toLowerCase()}s`), one: hasPrimaryKey ? (0, inflection_utils_1.safeInflection)(() => inflection.tableFieldName?.(resource), tableType.toLowerCase()) : null, create: (0, inflection_utils_1.safeInflection)(() => inflection.createField?.(resource), `create${tableType}`), update: hasPrimaryKey ? (0, inflection_utils_1.safeInflection)(() => inflection.updateByKeys?.(resource), `update${tableType}`) : null, delete: hasPrimaryKey ? (0, inflection_utils_1.safeInflection)(() => inflection.deleteByKeys?.(resource), `delete${tableType}`) : null, }; }