Urigo / SOFA

The best way to create REST APIs - Generate RESTful APIs from your GraphQL Server
https://www.the-guild.dev/graphql/sofa-api
MIT License
1.08k stars 88 forks source link

Not working with Nestjs #1346

Open rafakwolf opened 1 year ago

rafakwolf commented 1 year ago

I'm attempting to use Sofa in a Nestjs app, but the Rest endpoints are not receiving the data from post requests.

Here's an example https://github.com/rafakwolf/nestjs-sofa-poc

2627500295 commented 1 year ago

Here's how I use it with Nest.

const application = await NestFactory.create(AppModule, {
    bodyParser: true,
    rawBody: true,
  });
import { Request, Response, NextFunction } from 'express';

export function restoreBody(
  req: Request & { rawBody: Uint8Array },
  _res: Response,
  next: NextFunction
) {
  if (req.rawBody) {
    req.body = req.rawBody;
  }
  next();
}

export default restoreBody;
const app = this.httpAdapterHost.httpAdapter.getInstance();

const sofa = useSofa({
  ...
});

app.use('/api', restoreBody, sofa);
yuraxdrumz commented 1 year ago

Is is possible to get a full example of how you use sofa with Nestjs? @2627500295