Skip to content

Commit c98d0ee

Browse files
authored
Add nest.js example (#302)
1 parent 1026bef commit c98d0ee

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/pages/postgraphile/usage-library.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ Next we need an adaptor to convert a generic PostGraphile route handler into a
117117
handler that's suitable for your given server framework. We provide the
118118
following out of the box:
119119

120-
- `PostGraphileResponseNode` - for Node, Express, Connect, Restify, and Fastify
121-
v2 (NOT v3)
120+
- `PostGraphileResponseNode` - for Node, Express, Connect, Nest, Restify, and
121+
Fastify v2 (NOT v3)
122122
- `PostGraphileResponseKoa` - for Koa
123123
- `PostGraphileResponseFastify3` - for Fastify v3
124124

@@ -218,6 +218,28 @@ if (middleware.options.watchPg) {
218218
}
219219
```
220220

221+
For Nest, this might look something like:
222+
223+
```js
224+
import { Controller, Get, Post, Req, Next, Res } from '@nestjs/common';
225+
import { Request, Response } from 'express';
226+
import { PostGraphileResponseNode } from 'postgraphile';
227+
import { middleware } from './postgraphile.middleware';
228+
229+
@Controller('/')
230+
export class PostGraphileController {
231+
@Get(middleware.graphiqlRoute)
232+
graphiql (@Req() request: Request, @Res() response: Response, @Next() next) {
233+
middleware.graphiqlRouteHandler(new PostGraphileResponseNode(request, response, next));
234+
}
235+
236+
@Post(middleware.graphqlRoute)
237+
graphql (@Req() request: Request, @Res() response: Response, @Next() next) {
238+
middleware.graphqlRouteHandler(new PostGraphileResponseNode(request, response, next));
239+
}
240+
}
241+
```
242+
221243
**IMPORTANT**: although it's tempting to add your handlers with explicitly
222244
written paths, e.g. `app.post('/graphql', ...)`, it's better to use the relevant
223245
middleware properties such as `middleware.graphqlRoute` to ensure that

0 commit comments

Comments
 (0)