CodeGenieApp / CodeGenieApp/serverless-express

NestJS & Unable to determine event source based on event

Aperta
#658 6 commenti 3 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
5.3k
Fork
676
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Hi guys,

First of al thanks for the great plugin - helps a lot!
Unfortunately I have a small problem when I'm trying to use it together with NestJS and GraphQL.

When I'm executing `sls invoke local -f api` I'm getting:

```
{
"errorMessage": "Unable to determine event source based on event.",
"errorType": "Error",
"stackTrace": [
"Error: Unable to determine event source based on event.",
" at getEventSourceNameBasedOnEvent (/Users/lolo/Sites/app/node_modules/@vendia/serverless-express/src/event-sources/utils.js:127:9)",
" at proxy (/Users/lolo/Sites/app/node_modules/@vendia/serverless-express/src/configure.js:38:51)",
" at handler (/Users/lolo/Sites/app/node_modules/@vendia/serverless-express/src/configure.js:99:12)",
" at handler (/Users/lolo/Sites/app/src/events/api.ts:35:10)"
]
}
```

My setup is similar to the [example](https://github.com/vendia/serverless-express/tree/mainline/examples/basic-starter-nestjs) but of course much more advanced (I use additional GraphQL).

Below my setup:
--------
**serverless.yml**

```yaml
service: tmp-app

frameworkVersion: '3'
useDotenv: true

plugins:
- serverless-offline

package:
excludeDevDependencies: true
individually: true

provider:
name: aws
runtime: nodejs18.x
architecture: arm64
region: ${opt:region, 'eu-central-1'}
stage: ${opt:stage, 'dev'}
memorySize: 2048
versionFunctions: false
logRetentionInDays: 1

functions:
api:
handler: ./src/events/api.handler
events:
- httpApi:
path: /{proxy+}
method: ANY
```

**./src/events/api.ts**

```ts
import { ExpressAdapter } from '@nestjs/platform-express';
import serverlessExpress from '@vendia/serverless-express';
import { NestFactory } from '@nestjs/core';
import { APIGatewayProxyEventV2, Callback, Context, Handler } from 'aws-lambda';
import express from 'express';

import { AppModule } from './app.module';

let server: Handler;

export const handler: Handler = async (
event: APIGatewayProxyEventV2,
context: Context,
callback: Callback,
): Promise => {
if (!server) {
const expressApp = express();

const app = await NestFactory.create(AppModule, new ExpressAdapter(expressApp))
await app.init();

server = serverlessExpress({ app: expressApp });
}

return server(event, context, callback);
};
```

**./app.module.ts**

```ts
import { ApolloDriverConfig } from '@nestjs/apollo';
import { Module, NestModule } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';

const IS_PROD = process.env.NODE_ENV === 'production';

@Module({
imports: [
GraphQLModule.forRoot({
driver: ApolloDriver,
autoSchemaFile: IS_PROD ? undefined : `${process.cwd()}/src/schema.graphql`,
typePaths: IS_PROD ? ['./**/*.graphql'] : undefined,
autoTransformHttpErrors: true,
buildSchemaOptions: {
// Refs. https://docs.nestjs.com/graphql/scalars#code-first
dateScalarMode: 'timestamp',
},
introspection: true,
installSubscriptionHandlers: true,
sortSchema: true,
}),
],
})
export class AppModule implements NestModule {}
```

**./nest-cli.json**

```json
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"assets": [
{ "include": "**/*.graphql", "watchAssets": true }
],
"plugins": [
{
"name": "@nestjs/graphql",
"options": {
"introspectComments": true
}
}
]
}
}
```

Any ideas what is wrong?

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Riproduci il malfunzionamento con `sls invoke local -f api` utilizzando `src/events/api.ts` e la configurazione NestJS/GraphQL mostrata. Inizia da `getEventSourceNameBasedOnEvent` in `@vendia/serverless-express/src/event-sources/utils.js` e determina quale forma dell’evento o configurazione non è supportata; il lavoro è completato quando l’invocazione locale dell’API gestisce questa configurazione senza l’errore dell’origine dell’evento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
aws, express, graphql, node.js, typescript
Ambito
api, backend, cloud
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Da chiarire
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.