Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes based on Olympia/Giza workarounds #7

Merged
merged 6 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@joystream/warthog",
"version": "2.40.0",
"version": "2.41.0",
"description": "Opinionated set of tools for setting up GraphQL backed by TypeORM",
"main": "dist/index.js",
"types": "dist/types/index.d.ts",
Expand Down Expand Up @@ -32,8 +32,7 @@
"test:watch": "./tools/test.sh --watch"
},
"husky": {
"hooks": {
}
"hooks": {}
},
"repository": {
"type": "git",
Expand Down
15 changes: 9 additions & 6 deletions src/core/BaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
RelayPageOptions,
RelayService
} from './RelayService';
import * as shortid from 'shortid';

export interface BaseOptions {
manager?: EntityManager; // Allows consumers to pass in a TransactionManager
Expand Down Expand Up @@ -630,10 +631,10 @@ namespace RelationsManager {
qb: tmpQb
};
// setup SQL join and where conditions
common(tmpParameters, localIdColumn, foreignTableName, foreignColumnMap, foreignColumnName);
const foreignTableAlias = common(tmpParameters, localIdColumn, foreignTableName, foreignColumnMap, foreignColumnName);

// convert where clause created for temporary query builder into "every" form
const foreingIdColumn = `"${foreignTableName}"."${foreignColumnMap[foreignColumnName]}"`;
const foreingIdColumn = `"${foreignTableAlias}"."${foreignColumnMap[foreignColumnName]}"`;
parameters.qb.andHaving(
`COUNT(${foreingIdColumn}) = COUNT(CASE WHEN ${tmpQb.expressionMap.wheres[0].condition} THEN 1 ELSE NULL END)`,
tmpQb.expressionMap.parameters
Expand Down Expand Up @@ -766,17 +767,19 @@ namespace RelationsManager {
foreignTableName: string,
foreignColumnMap: StringMap,
foreignColumnName: string
) {
const foreingIdColumn = `"${foreignTableName}"."${foreignColumnMap[foreignColumnName]}"`;
): string {
const foreignTableAlias = shortid.generate();
const foreingIdColumn = `"${foreignTableAlias}"."${foreignColumnMap[foreignColumnName]}"`;

// join must be performed on `topLevelQb` (it would be ignored on `qb` in some cases)
parameters.topLevelQb.leftJoin(
foreignTableName,
foreignTableName,
foreignTableAlias,
`${localIdColumn} = ${foreingIdColumn}`
);

addWhereCondition(parameters, foreignTableName, foreignColumnMap);
addWhereCondition(parameters, foreignTableAlias, foreignColumnMap);
return foreignTableAlias;
}

/*
Expand Down
8 changes: 6 additions & 2 deletions src/core/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface ServerOptions<T> {
queryTemplates?: IQueryTemplate[];
version?: string;
cdnUrl?: string;
subscriptionEndpoint?: string;
};
onBeforeGraphQLMiddleware?: (app: express.Application) => void;
onAfterGraphQLMiddleware?: (app: express.Application) => void;
Expand Down Expand Up @@ -242,8 +243,11 @@ export class Server<C extends BaseContext> {
? {
playground: {
// this makes playground files to be served locally
version: this.appOptions.playgroundConfig?.version || '',
cdnUrl: this.appOptions.playgroundConfig?.cdnUrl || '',
version: this.appOptions.playgroundConfig?.version,
cdnUrl: this.appOptions.playgroundConfig?.cdnUrl,

// allow setting custom subscription endpoint
subscriptionEndpoint: this.appOptions.playgroundConfig?.subscriptionEndpoint,

// pass custom query templates to playground
queryTemplates: this.appOptions.playgroundConfig?.queryTemplates || []
Expand Down
16 changes: 6 additions & 10 deletions src/middleware/DataLoaderMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { MiddlewareInterface, NextFn, ResolverData } from 'type-graphql';
import { Service } from 'typedi';

import { BaseContext } from '../core';
import { RelationIdLoader } from '../torm/RelationIdLoader';

interface Deleteable {
deletedAt?: string;
Expand Down Expand Up @@ -37,16 +36,13 @@ export class DataLoaderMiddleware implements MiddlewareInterface<BaseContext> {
if (Array.isArray(entities) && entities[0] && Array.isArray(entities[0])) {
throw new Error('You must flatten arrays of arrays of entities');
}
return new RelationIdLoader(context.connection)
.loadManyToManyRelationIdsAndGroup(relation, entities)
.then(groups => {
return groups.map(group => {
if (Array.isArray(group.related)) {
return group.related.filter((item: Deleteable) => !item.deletedAt);
}
return group.related;
});
return Promise.all(
entities.map(entity => context.connection.relationLoader.load(relation, entity))
).then(function(results) {
return results.map(function(related) {
return relation.isManyToOne || relation.isOneToOne ? related[0] : related;
});
});
});
}
});
Expand Down
Loading