-
-
Notifications
You must be signed in to change notification settings - Fork 526
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
Non eager joins fail on serverless #313
Comments
Locally, run via If I run via If I set eager to true in join options for each join, everything works. @Crud({
model: { type: Ad },
query: {
exclude: ['createdAt', 'updatedAt'],
join: {
'applications': {},
'applications.user': {},
'applications.type': {},
// ...
},
limit: 10,
cache: 1,
},
routes: {
only: ['getOneBase', 'getManyBase'],
},
})
@Controller('api/public/ads')
@ApiUseTags('Public/Ads')
export class AdPublicController implements CrudController<Ad> {
constructor(public service: AdService) {}
} import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, ManyToOne, ManyToMany, JoinTable, OneToMany } from 'typeorm';
import { IsArray, IsBoolean, IsDate, IsDecimal, IsInt, IsOptional, IsString, ValidateNested } from 'class-validator';
import { ApiModelProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { AdApplication } from './adApplication.entity';
@Entity('ad')
export class Ad {
@ApiModelProperty({ required: false, description: 'Id', readOnly: true })
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id: number;
@ApiModelProperty({ required: false, description: 'Date created', readOnly: true, type: Date, example: '2019-09-12 14:22:57.358854000' })
@CreateDateColumn({ nullable: true })
createdAt?: Date;
@ApiModelProperty({ required: false, description: 'Date updated', readOnly: true, type: Date, example: '2019-09-12 14:22:57.358854000' })
@UpdateDateColumn({ nullable: true })
updatedAt?: Date;
// ...
@ApiModelProperty({ required: false, isArray: true, type: [AdApplication], description: 'Array of applications' })
@IsArray()
@IsOptional({ always: true })
@ValidateNested({ each: true })
@Type(() => AdApplication)
@OneToMany(type => AdApplication, adApplication => adApplication.ad)
applications: AdApplication[];
} import { CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, Unique } from 'typeorm';
import { IsDefined, IsNotEmpty } from 'class-validator';
import { ApiModelProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { Ad } from './ad.entity';
@Entity('adApplication')
export class AdApplication {
@ApiModelProperty({ required: false, description: 'Id', readOnly: true })
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id: number;
@ApiModelProperty({ required: true, description: 'Applied user', type: User })
@IsNotEmpty()
@IsDefined()
@Type(() => User)
@ManyToOne(type => User, user => user.applications)
user: User;
@ApiModelProperty({ required: true, description: 'Ad', type: Ad })
@IsNotEmpty()
@IsDefined()
@Type(() => Ad)
@ManyToOne(type => Ad, ad => ad.applications)
ad: Ad;
@ApiModelProperty({ required: true, description: 'Ad application type', type: AdApplicationType })
@IsNotEmpty()
@IsDefined()
@Type(() => AdApplicationType)
@ManyToOne(type => AdApplicationType)
type: AdApplicationType;
@ApiModelProperty({ required: false, description: 'Date created', readOnly: true, type: Date, example: '2019-09-12 14:22:57.358854000' })
@CreateDateColumn({ nullable: false })
createdAt: Date;
} import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
import { IsDefined, IsOptional, IsString } from 'class-validator';
import { ApiModelProperty } from '@nestjs/swagger';
@Entity('adApplicationType')
export class AdApplicationType {
@PrimaryGeneratedColumn({ type: 'int', name: 'id' })
id: number;
@ApiModelProperty({ required: false, description: 'Date created', readOnly: true, type: Date, example: '2019-09-12 14:22:57.358854000' })
@CreateDateColumn({ nullable: true })
createdAt?: Date;
@ApiModelProperty({ required: false, description: 'Date updated', readOnly: true, type: Date, example: '2019-09-12 14:22:57.358854000' })
@UpdateDateColumn({ nullable: true })
updatedAt?: Date;
@ApiModelProperty({ required: true, description: 'Name', maxLength: 128 })
@IsString()
@IsDefined()
@IsDefined({ always: true })
@Column({ nullable: false, length: 128 })
name: string;
@ApiModelProperty({ required: false, description: 'Description' })
@IsString()
@IsOptional()
@Column({ nullable: true })
description: string;
} |
Also, on sls, only the last join parameter is actually joined, if the joins are not eager... |
what about using |
I tried, but it ddn't work. I follow this https://github.com/nestjsx/crud/wiki/Requests#join The strange thing is that this only fails on serverless. And, even stranger, it works if all joins are eager. |
nothing strange here. It looks like serverless doesn't support express like query parsing. |
Hmmm, true... Nest.js runs on serverless via an ExpressAdapter as the handler. // src/lambda.ts
import { Handler, Context } from 'aws-lambda';
import { Server } from 'http';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ExpressAdapter } from '@nestjs/platform-express';
import * as serverless from 'aws-serverless-express';
import { proxy } from 'aws-serverless-express';
import { ValidationParamPipe } from './pipes/validation.param.pipe';
import { HttpExceptionFilter } from './exceptions/exceptions.filter';
import { NetworkInterceptor } from './interceptors/network.interceptor';
const binaryMimeTypes: string[] = [];
let cachedServer: Server;
process.on('unhandledRejection', (reason) => {
// tslint:disable-next-line:no-console
console.error(reason);
});
process.on('uncaughtException', (reason) => {
// tslint:disable-next-line:no-console
console.error(reason);
});
function bootstrapServer(): Promise<Server> {
const expressApp = require('express')();
const adapter = new ExpressAdapter(expressApp);
return NestFactory.create(AppModule, adapter)
.then(app => app.enableCors())
.then(app => app.useGlobalPipes(new ValidationParamPipe()))
.then(app => app.useGlobalInterceptors(new NetworkInterceptor()))
.then(app => app.useGlobalFilters(new HttpExceptionFilter()))
.then(app => app.init())
.then(() => serverless.createServer(expressApp));
}
export const handler: Handler = async (event: any, context: Context) => {
cachedServer = await bootstrapServer();
return proxy(cachedServer, event, context, 'PROMISE').promise;
}; # severless.yml
# ...
functions:
main:
handler: src/lambda.handler
events:
- http:
method: any
path: /api/{proxy+}
cors: true But, I guess you already know all this... 😃 Have you had similar problems? Any more advice to try? |
CodeGenieApp/serverless-express#214 |
I have same issue with Azure Function HTTP, join only works when i set eager equals true. |
Woaah, same issue here. Any hopes for the future? |
Besides setting the nested entity as eager... Is there any other workaround for this issue? TBH, I am not sure if waiting for Amazon to fix the issue will help. It is a bit concerning how aws-serverless is maintained by Amazon... for what I see, the last commit on the aws-serverless-express was done in April... |
I raised a support issue to AWS to ask for the status of their aws-serverless-express project. The response was that it will still be maintained, but they will do some "roadmap with prioritization" of the issues in Github "sometime in 2020"... So, it would be nice not to have to wait for them to get around to fix this... would it be an option to use multiple joins with sligtly different names, to avoid the params from dissapearing? examples:
What do you think? |
So in that case we need to add a support for joins as an object and not only arrays |
No description provided.
The text was updated successfully, but these errors were encountered: