Browse Source

fix: GQL relation bugs

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/852/head
Pranav C 3 years ago
parent
commit
e07813d34e
  1. 2
      packages/nocodb/src/example/docker.ts
  2. 46
      packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts
  3. 6
      packages/nocodb/src/lib/noco/gql/GqlApiBuilder.ts
  4. 4
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

2
packages/nocodb/src/example/docker.ts

@ -15,7 +15,7 @@ server.set('view engine', 'ejs');
// process.env[`NC_DB`] = `mysql2://localhost:3306?u=root&p=password&d=mar_21`;
// process.env[`NC_DB`] = `pg://localhost:3306?u=root&p=password&d=mar_24`;
// process.env[`NC_DB`] = `pg://localhost:5432?u=postgres&p=xgene&d=abcde`;
// process.env[`NC_DB`] = `pg://localhost:5432?u=postgres&p=password&d=abcde`;
// process.env[`NC_TRY`] = 'true';
// process.env[`NC_DASHBOARD_URL`] = '/test';

46
packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts

@ -2002,23 +2002,27 @@ class BaseModelSql extends BaseModel {
const childs = await this._run(
this._paginateAndSort(
this.dbDriver.union(
ids.map(p => {
const query = this.dbDriver(this.dbModels[child].tnPath)
.where({ [cn]: p })
.conditionGraph(conditionGraph)
.xwhere(where, this.selectQuery(''))
// .select(...fields.split(','));
.select(this.dbModels?.[child]?.selectQuery(fields));
this._paginateAndSort(query, { limit, offset }, child);
return this.isSqlite()
? this.dbDriver.select().from(query)
: query;
}),
!this.isSqlite()
this.dbDriver.queryBuilder().from(
this.dbDriver
.union(
ids.map(p => {
const query = this.dbDriver(this.dbModels[child].tnPath)
.where({ [cn]: p })
.conditionGraph(conditionGraph)
.xwhere(where, this.selectQuery(''))
// .select(...fields.split(','));
.select(this.dbModels?.[child]?.selectQuery(fields));
this._paginateAndSort(query, { limit, offset }, child);
return this.isSqlite()
? this.dbDriver.select().from(query)
: query;
}),
!this.isSqlite()
)
.as('list')
),
{ sort, limit: 1000 } as any,
{ sort, ignoreLimit: true } as any,
child
)
);
@ -2093,11 +2097,17 @@ class BaseModelSql extends BaseModel {
*/
_paginateAndSort(
query,
{ limit = 20, offset = 0, sort = '' }: XcFilter,
{
limit = 20,
offset = 0,
sort = '',
ignoreLimit = false
}: XcFilter & { ignoreLimit?: boolean },
table?: string,
isUnion?: boolean
) {
query.offset(offset).limit(limit);
query.offset(offset);
if (!ignoreLimit) query.limit(limit);
if (!table && !sort && this.clientType === 'mssql' && !isUnion) {
sort =

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

@ -1898,10 +1898,10 @@ export class GqlApiBuilder extends BaseApiBuilder<Noco> implements XcMetaMgr {
// create count loader with middleware
{
const mw = new GqlMiddleware(this.acls, tnc, '', this.models);
this.addHmListResolverMethodToType(
tnp,
hm,
this.addHmCountResolverMethodToType(
mw,
hm,
tnp,
{},
countPropName,
this.models[hm.rtn]?.columnToAlias[hm.rcn]

4
packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

@ -1485,6 +1485,10 @@ export default class NcMetaMgr {
result = await this.xcTableAndViewList(req, args);
break;
case 'tableList':
result = await this.xcTableList(req, args);
break;
case 'columnList':
result = await this.xcColumnList(args);
break;

Loading…
Cancel
Save