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

fix(router): get middlewares route bug fixed #153

Merged
merged 1 commit into from
May 13, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import {
ConduitRouteParameters,
ConduitRouteReturnDefinition,
ConduitString,
TYPE,
} from '@conduitplatform/commons';
import { ConduitDefaultRouter } from '../..';
import { generate } from '@graphql-codegen/cli';
import path from 'path';
import { status } from '@grpc/grpc-js';
import fs, { unlink } from 'fs';
import { isEmpty } from 'lodash';
import { GrpcError } from '@conduitplatform/grpc-sdk';

export function generateGraphQlClient(router: ConduitDefaultRouter) {
export function generateGraphQlClient() {
return new ConduitRoute(
{
path: '/router/generate/graphql',
Expand Down
5 changes: 1 addition & 4 deletions packages/router/src/admin/routes/GenerateRestClient.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ import {
ConduitRouteReturnDefinition,
ConduitString,
ConduitError,
TYPE,
} from '@conduitplatform/commons';
import { ConduitDefaultRouter } from '../..';
const util = require('util');
const exec = util.promisify(require('child_process').exec);
import path from 'path';
import url from 'url';
import fs, { unlink } from 'fs';
import { status } from '@grpc/grpc-js';

export function generateRestClient(router: ConduitDefaultRouter) {
export function generateRestClient() {
return new ConduitRoute(
{
path: '/router/generate/rest',
Expand Down
9 changes: 6 additions & 3 deletions packages/router/src/admin/routes/GetMiddlewares.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TYPE,
} from '@conduitplatform/commons';
import { ConduitDefaultRouter } from '../../index';
import { isNil } from 'lodash';

export function getMiddlewares(router: ConduitDefaultRouter) {
return new ConduitRoute(
Expand All @@ -16,16 +17,18 @@ export function getMiddlewares(router: ConduitDefaultRouter) {
response: TYPE.JSON,
}),
async () => {
let response: any [] = [];
let response: string [] = [];
const module = router.getGrpcRoutes();
Object.keys(module).forEach((url: string) => {
module[url].forEach((item: any) => {
if (item.returns == null && item.grpcFunction !== "") {
if (item.returns == null && !isNil(item.grpcFunction) && item.grpcFunction !== '') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need the !isNil() here? Null / Undefined don't match ''.

response.push(item.grpcFunction);
}
});
});
return { result: response }; // unnested from result in Rest.addConduitRoute, grpc routes avoid this using wrapRouterGrpcFunction
// @ts-ignore
let actualResponse = Array.from(new Set(response));
return { result: actualResponse }; // unnested from result in Rest.addConduitRoute, grpc routes avoid this using wrapRouterGrpcFunction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a variable, return this directly.

},
);
}
4 changes: 2 additions & 2 deletions packages/router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ export class ConduitDefaultRouter implements IConduitRouter {
private registerAdminRoutes() {
this._commons.getAdmin().registerRoute(adminRoutes.getRoutes(this));
this._commons.getAdmin().registerRoute(adminRoutes.getMiddlewares(this));
this._commons.getAdmin().registerRoute(adminRoutes.generateRestClient(this));
this._commons.getAdmin().registerRoute(adminRoutes.generateGraphQlClient(this));
this._commons.getAdmin().registerRoute(adminRoutes.generateRestClient());
this._commons.getAdmin().registerRoute(adminRoutes.generateGraphQlClient());
}

setConfig(moduleConfig: any) {
Expand Down