|
|
@ -1,13 +1,4 @@ |
|
|
|
import GqlResolver from "./GqlResolver"; |
|
|
|
import GqlResolver from "./GqlResolver"; |
|
|
|
|
|
|
|
|
|
|
|
import inflection from 'inflection'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// import {
|
|
|
|
|
|
|
|
// ExpressXcTsPolicyGql,
|
|
|
|
|
|
|
|
// GqlXcSchemaFactory,
|
|
|
|
|
|
|
|
// ModelXcMetaFactory
|
|
|
|
|
|
|
|
// } from "nc-help";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import {BaseType} from 'xc-core-ts'; |
|
|
|
import {BaseType} from 'xc-core-ts'; |
|
|
|
import {DbConfig, NcConfig} from "../../../interface/config"; |
|
|
|
import {DbConfig, NcConfig} from "../../../interface/config"; |
|
|
|
import Noco from "../Noco"; |
|
|
|
import Noco from "../Noco"; |
|
|
@ -391,7 +382,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr { |
|
|
|
const colNameAlias = self.models[bt.tn]?.columnToAlias[bt.cn]; |
|
|
|
const colNameAlias = self.models[bt.tn]?.columnToAlias[bt.cn]; |
|
|
|
const rcolNameAlias = self.models[bt.rtn]?.columnToAlias[bt.rcn]; |
|
|
|
const rcolNameAlias = self.models[bt.rtn]?.columnToAlias[bt.rcn]; |
|
|
|
const middlewareBody = middlewaresArr.find(({title}) => title === bt.rtn)?.functions?.[0]; |
|
|
|
const middlewareBody = middlewaresArr.find(({title}) => title === bt.rtn)?.functions?.[0]; |
|
|
|
const propName = `${inflection.camelize(bt._rtn, false)}Read`; |
|
|
|
const propName = `${bt._rtn}Read`; |
|
|
|
if (propName in this.types[tn].prototype) { |
|
|
|
if (propName in this.types[tn].prototype) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
@ -702,8 +693,8 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr { |
|
|
|
|
|
|
|
|
|
|
|
const colNameAlias = self.models[hm.rtn]?.columnToAlias[hm.rcn]; |
|
|
|
const colNameAlias = self.models[hm.rtn]?.columnToAlias[hm.rcn]; |
|
|
|
|
|
|
|
|
|
|
|
const countPropName = `${inflection.camelize(hm._tn, false)}Count`; |
|
|
|
const countPropName = `${hm._tn}Count`; |
|
|
|
const listPropName = `${inflection.camelize(hm._tn, false)}List`; |
|
|
|
const listPropName = `${hm._tn}List`; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.log(`xcTablesPopulate : Populating '%s' and '%s' loaders`, listPropName, countPropName); |
|
|
|
this.log(`xcTablesPopulate : Populating '%s' and '%s' loaders`, listPropName, countPropName); |
|
|
@ -747,7 +738,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr { |
|
|
|
|
|
|
|
|
|
|
|
for (const bt of schema.belongsTo) { |
|
|
|
for (const bt of schema.belongsTo) { |
|
|
|
const colNameAlias = self.models[bt.tn]?.columnToAlias[bt.cn]; |
|
|
|
const colNameAlias = self.models[bt.tn]?.columnToAlias[bt.cn]; |
|
|
|
const propName = `${inflection.camelize(bt._rtn, false)}Read`; |
|
|
|
const propName = `${bt._rtn}Read`; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (propName in this.types[tn].prototype) { |
|
|
|
if (propName in this.types[tn].prototype) { |
|
|
@ -1369,7 +1360,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr { |
|
|
|
|
|
|
|
|
|
|
|
/* update parent table meta and resolvers */ |
|
|
|
/* update parent table meta and resolvers */ |
|
|
|
{ |
|
|
|
{ |
|
|
|
const columns = await this.getColumnList(tnp); |
|
|
|
const columns = this.metas[tnp]?.columns;//await this.getColumnList(tnp);
|
|
|
|
const hasMany = this.extractHasManyRelationsOfTable(relations, tnp); |
|
|
|
const hasMany = this.extractHasManyRelationsOfTable(relations, tnp); |
|
|
|
const belongsTo = this.extractBelongsToRelationsOfTable(relations, tnp); |
|
|
|
const belongsTo = this.extractBelongsToRelationsOfTable(relations, tnp); |
|
|
|
const ctx = this.generateContextForTable(tnp, columns, relations, hasMany, belongsTo); |
|
|
|
const ctx = this.generateContextForTable(tnp, columns, relations, hasMany, belongsTo); |
|
|
@ -1385,18 +1376,20 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr { |
|
|
|
const oldMeta = JSON.parse(existingModel.meta); |
|
|
|
const oldMeta = JSON.parse(existingModel.meta); |
|
|
|
Object.assign(oldMeta, { |
|
|
|
Object.assign(oldMeta, { |
|
|
|
hasMany: meta.hasMany, |
|
|
|
hasMany: meta.hasMany, |
|
|
|
schema: this.schemas[tnp] |
|
|
|
v: oldMeta.v.filter(({hm}) => !hm || hm.rtn !== tnp || hm.tn !== tnc) |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
// todo: backup schema
|
|
|
|
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', { |
|
|
|
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', { |
|
|
|
title: tnp, |
|
|
|
title: tnp, |
|
|
|
meta: JSON.stringify(oldMeta) |
|
|
|
meta: JSON.stringify(oldMeta), |
|
|
|
|
|
|
|
schema: this.schemas[tnp] |
|
|
|
}, {'title': tnp}) |
|
|
|
}, {'title': tnp}) |
|
|
|
this.metas[tnp] = oldMeta; |
|
|
|
this.models[tnp] = this.getBaseModel(oldMeta); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const countPropName = `${inflection.camelize(this.getTableNameAlias(tnc), false)}Count`; |
|
|
|
const countPropName = `${this.getTableNameAlias(tnc)}Count`; |
|
|
|
const listPropName = `${inflection.camelize(this.getTableNameAlias(tnc), false)}List`; |
|
|
|
const listPropName = `${this.getTableNameAlias(tnc)}List`; |
|
|
|
|
|
|
|
|
|
|
|
this.log(`onRelationDelete : Deleting '%s' and '%s' loaders`, countPropName, listPropName); |
|
|
|
this.log(`onRelationDelete : Deleting '%s' and '%s' loaders`, countPropName, listPropName); |
|
|
|
/* defining HasMany list method within GQL Type class */ |
|
|
|
/* defining HasMany list method within GQL Type class */ |
|
|
@ -1432,15 +1425,17 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr { |
|
|
|
const oldMeta = JSON.parse(existingModel.meta); |
|
|
|
const oldMeta = JSON.parse(existingModel.meta); |
|
|
|
Object.assign(oldMeta, { |
|
|
|
Object.assign(oldMeta, { |
|
|
|
belongsTo: meta.belongsTo, |
|
|
|
belongsTo: meta.belongsTo, |
|
|
|
|
|
|
|
v: oldMeta.v.filter(({bt}) => !bt || bt.rtn !== tnp || bt.tn !== tnc) |
|
|
|
}); |
|
|
|
}); |
|
|
|
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', { |
|
|
|
await this.xcMeta.metaUpdate(this.projectId, this.dbAlias, 'nc_models', { |
|
|
|
title: tnc, |
|
|
|
title: tnc, |
|
|
|
meta: JSON.stringify(oldMeta) |
|
|
|
meta: JSON.stringify(oldMeta), |
|
|
|
|
|
|
|
schema: this.schemas[tnc] |
|
|
|
}, {'title': tnc}); |
|
|
|
}, {'title': tnc}); |
|
|
|
this.metas[tnc] = oldMeta; |
|
|
|
this.models[tnc] = this.getBaseModel(oldMeta); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const propName = `${inflection.camelize(this.getTableNameAlias(tnp), false)}Read`; |
|
|
|
const propName = `${this.getTableNameAlias(tnp)}Read`; |
|
|
|
this.log(`onRelationDelete : Deleting '%s' loader`, propName); |
|
|
|
this.log(`onRelationDelete : Deleting '%s' loader`, propName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|