Browse Source

feat: sync gql implementation

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/894/head
Pranav C 3 years ago
parent
commit
6c93d9d6f4
  1. 62
      packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts

62
packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts

@ -14,7 +14,9 @@ import ModelXcMetaFactory from '../../sqlMgr/code/models/xc/ModelXcMetaFactory';
import NcHelp from '../../utils/NcHelp'; import NcHelp from '../../utils/NcHelp';
import NcProjectBuilder from '../NcProjectBuilder'; import NcProjectBuilder from '../NcProjectBuilder';
import Noco from '../Noco'; import Noco from '../Noco';
import BaseApiBuilder from '../common/BaseApiBuilder'; import BaseApiBuilder, {
XcTablesPopulateParams
} from '../common/BaseApiBuilder';
import NcMetaIO from '../meta/NcMetaIO'; import NcMetaIO from '../meta/NcMetaIO';
import { m2mNotChildren, m2mNotChildrenCount } from './GqlCommonResolvers'; import { m2mNotChildren, m2mNotChildrenCount } from './GqlCommonResolvers';
@ -710,16 +712,7 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
}); });
} }
public async xcTablesPopulate(args?: { public async xcTablesPopulate(args?: XcTablesPopulateParams): Promise<any> {
tableNames?: Array<{
tn: string;
_tn?: string;
}>;
type?: 'table' | 'view';
columns?: {
[key: string]: any;
};
}): Promise<any> {
this.log( this.log(
'xcTablesPopulate : names - %o , type - %s', 'xcTablesPopulate : names - %o , type - %s',
args?.tableNames, args?.tableNames,
@ -751,20 +744,22 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
if (args?.tableNames?.length) { if (args?.tableNames?.length) {
const relatedTableList = []; const relatedTableList = [];
// extract tables which have relation with the tables in list
for (const r of relations) { if (!args?.oldMetas)
if (args.tableNames.some(t => t.tn === r.tn)) { // extract tables which have relation with the tables in list
if (!relatedTableList.includes(r.rtn)) { for (const r of relations) {
relatedTableList.push(r.rtn); if (args.tableNames.some(t => t.tn === r.tn)) {
await this.onTableDelete(r.rtn); if (!relatedTableList.includes(r.rtn)) {
} relatedTableList.push(r.rtn);
} else if (args.tableNames.some(t => t.tn === r.rtn)) { await this.onTableDelete(r.rtn);
if (!relatedTableList.includes(r.tn)) { }
relatedTableList.push(r.tn); } else if (args.tableNames.some(t => t.tn === r.rtn)) {
await this.onTableDelete(r.tn); if (!relatedTableList.includes(r.tn)) {
relatedTableList.push(r.tn);
await this.onTableDelete(r.tn);
}
} }
} }
}
tables = args.tableNames.map(({ tn, _tn }) => ({ tables = args.tableNames.map(({ tn, _tn }) => ({
tn, tn,
@ -887,6 +882,9 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
table.tn, table.tn,
table.type table.type
); );
ctx.oldMeta = args?.oldMetas?.[table.tn];
/**************** prepare table models and policies ****************/ /**************** prepare table models and policies ****************/
this.metas[table.tn] = ModelXcMetaFactory.create( this.metas[table.tn] = ModelXcMetaFactory.create(
this.connectionConfig, this.connectionConfig,
@ -949,6 +947,24 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
alias: this.metas[table.tn]._tn alias: this.metas[table.tn]._tn
} }
); );
} else if (args?.oldMetas?.[table.tn]?.id) {
this.log(
"xcTablesPopulate : Updating model metadata for '%s' - %s",
table.tn,
table.type
);
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_models',
{
title: table.tn,
alias: this.metas[table.tn]._tn,
meta: JSON.stringify(this.metas[table.tn]),
type: table.type || 'table'
},
args?.oldMetas?.[table.tn]?.id
);
} }
this.log( this.log(

Loading…
Cancel
Save