Comparing version 0.0.4 to 0.0.5
@@ -131,6 +131,10 @@ "use strict"; | ||
resolver.addDerivedField(field, (row) => { | ||
var _a; | ||
const xid = row[xidColumn]; | ||
(0, assert_1.default)(typeof xid === 'string'); | ||
const typeName = queryResolver.getTypeNameFromRow(row); | ||
const actualMeta = (meta.objectTypes || metas).find((meta) => meta.typeName === typeName); | ||
// Need to check both metas (in case typeName is an interface with table) | ||
// and objectTypes (in case it is an object type with an interface table) | ||
const actualMeta = metas.find((meta) => meta.typeName === typeName) || | ||
((_a = meta.objectTypes) === null || _a === void 0 ? void 0 : _a.find((meta) => meta.typeName === typeName)); | ||
return actualMeta ? qualifyXid(xid, actualMeta) : xid; | ||
@@ -137,0 +141,0 @@ }); |
import { Dumpable, PropertyDumper } from 'dumpable'; | ||
import { Row } from './TableSpec'; | ||
import { FetchMap, ParentRowMap, ResultBuilder } from './internal'; | ||
import { Row } from './TableSpec'; | ||
export declare class FieldResolver<T = Row> extends Dumpable implements ResultBuilder<T> { | ||
private readonly fieldSources; | ||
protected addField(field: string, source: (data: T, parentRowMap: ParentRowMap, fetchMap: FetchMap) => unknown): this; | ||
protected addField(field: string, source: (data: T, parentRowMap: ParentRowMap, fetchMap: FetchMap) => unknown, sourceName?: string | undefined): this; | ||
addConstantField(field: string, value: unknown): this; | ||
@@ -8,0 +8,0 @@ addDerivedField(field: string, func: (data: T) => unknown): this; |
@@ -9,2 +9,3 @@ "use strict"; | ||
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal")); | ||
const util_1 = require("./util"); | ||
class FieldResolver extends dumpable_1.Dumpable { | ||
@@ -15,9 +16,9 @@ constructor() { | ||
} | ||
addField(field, source) { | ||
addField(field, source, sourceName = source.name || (util_1.devMode ? beautifyStack(new Error().stack) : undefined)) { | ||
const sources = this.fieldSources.get(field); | ||
if (!sources) { | ||
this.fieldSources.set(field, [source]); | ||
this.fieldSources.set(field, [[source, sourceName]]); | ||
} | ||
else { | ||
sources.push(source); | ||
sources.push([source, sourceName]); | ||
} | ||
@@ -27,3 +28,3 @@ return this; | ||
addConstantField(field, value) { | ||
return this.addField(field, () => value); | ||
return this.addField(field, () => value, 'constant'); | ||
} | ||
@@ -37,3 +38,4 @@ addDerivedField(field, func) { | ||
let value = null; | ||
for (const source of sources) { | ||
let valueSourceName = null; | ||
for (const [source, sourceName] of sources) { | ||
const sourceValue = source(data, parentRowMap, fetchMap); | ||
@@ -43,5 +45,14 @@ if (sourceValue != null) { | ||
value = sourceValue; | ||
valueSourceName = sourceName; | ||
} | ||
else if (!(0, fast_deep_equal_1.default)(value, sourceValue) && !isOrContainsOnlyEmptyConnections(sourceValue)) { | ||
throw new Error(`Conflicting values for field "${field}"`); | ||
let message = `Conflicting values for field "${field}": ` + JSON.stringify(value); | ||
if (valueSourceName) { | ||
message += ` from "${valueSourceName}"`; | ||
} | ||
message += ' != ' + JSON.stringify(sourceValue); | ||
if (sourceName) { | ||
message += ` from "${sourceName}"`; | ||
} | ||
throw new Error(message); | ||
} | ||
@@ -73,2 +84,12 @@ } | ||
} | ||
function beautifyStack(stack) { | ||
if (stack) { | ||
return stack | ||
.split('\n') | ||
.filter((line) => line !== 'Error' && !/node:internal/.test(line)) | ||
.map((line) => line.replace(/^\s*at\s+/, '')) | ||
.join(', '); | ||
} | ||
return stack; | ||
} | ||
//# sourceMappingURL=FieldResolver.js.map |
import { Json } from './api'; | ||
export declare const devMode: boolean; | ||
export declare function arrayEqual<T>(a: T[], b: T[], compare?: (a: T, b: T) => boolean): boolean; | ||
@@ -3,0 +4,0 @@ export declare function optionalArrayEqual<T>(a: T[] | null | undefined, b: T[] | null | undefined, compare?: (a: T, b: T) => boolean): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.assertJson = exports.notNull = exports.findMap = exports.optionalArrayEqual = exports.arrayEqual = void 0; | ||
exports.assertJson = exports.notNull = exports.findMap = exports.optionalArrayEqual = exports.arrayEqual = exports.devMode = void 0; | ||
exports.devMode = process.env.NODE_ENV !== 'production'; | ||
function arrayEqual(a, b, compare = (a, b) => a === b) { | ||
@@ -5,0 +6,0 @@ return a.length === b.length && a.every((v, i) => compare(v, b[i])); |
{ | ||
"name": "gqlsql", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "GraphQL SQL Resolver Builders", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
310503
3432