You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/exception-filters.md
+17-10Lines changed: 17 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -284,6 +284,8 @@ You can add as many filters with this technique as needed; simply add each to th
284
284
285
285
In order to catch **every** unhandled exception (regardless of the exception type), leave the `@Catch()` decorator's parameter list empty, e.g., `@Catch()`.
286
286
287
+
In the example below we have a code that is platform-agnostic because it uses the [HTTP adapter](./faq/http-adapter) to deliver the response, and doesn't use any of the platform-specific objects (`Request` and `Response`) directly:
In the example above the filter will catch each exception thrown, regardless of its type (class).
318
-
319
326
#### Inheritance
320
327
321
328
Typically, you'll create fully customized exception filters crafted to fulfill your application requirements. However, there might be use-cases when you would like to simply extend the built-in default **global exception filter**, and override the behavior based on certain factors.
Copy file name to clipboardExpand all lines: content/faq/serverless.md
+27-2Lines changed: 27 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -178,7 +178,7 @@ First, let's install the required packages:
178
178
179
179
```bash
180
180
$ npm i @vendia/serverless-express aws-lambda
181
-
$ npm i @types/aws-lambda serverless-offline
181
+
$ npm i -D @types/aws-lambda serverless-offline
182
182
```
183
183
184
184
> info **Hint** To speed up development cycles, we install the `serverless-offline` plugin which emulates AWS λ and API Gateway.
@@ -263,7 +263,7 @@ $ npx serverless offline
263
263
Once the application is running, open your browser and navigate to `http://localhost:3000/dev/[ANY_ROUTE]` (where `[ANY_ROUTE]` is any endpoint registered in your application).
264
264
265
265
In the sections above, we've shown that using `webpack` and bundling your app can have significant impact on the overall bootstrap time.
266
-
However, to make it work with our example, there's one additional configuration you must add in your `webpack.config.js` file. Generally,
266
+
However, to make it work with our example, there are a few additional configurations you must add in your `webpack.config.js` file. Generally,
267
267
to make sure our `handler` function will be picked up, we must change the `output.libraryTarget` property to `commonjs2`.
268
268
269
269
```javascript
@@ -280,6 +280,31 @@ return {
280
280
281
281
With this in place, you can now use `$ nest build --webpack` to compile your function's code (and then `$ npx serverless offline` to test it).
282
282
283
+
It's also recommended (but **not required** as it will slow down your build process) to install the `terser-webpack-plugin` package and override its configuration to keep classnames intact when minifying your production build. Not doing so can result in incorrect behavior when using `class-validator` within your application.
Alternatively, if you want to keep your function very lightweight and you don't need any HTTP-related features (routing, but also guards, interceptors, pipes, etc.),
Copy file name to clipboardExpand all lines: content/fundamentals/unit-testing.md
+48-8Lines changed: 48 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -160,6 +160,41 @@ Instead of using the production version of any provider, you can override it wit
160
160
161
161
<app-banner-courses></app-banner-courses>
162
162
163
+
#### Auto mocking
164
+
165
+
Nest also allows you to define a mock factory to apply to all of your missing dependencies. This is useful for cases where you have a large number of dependencies in a class and mocking all of them will take a long time and a lot of setup. To make use of this feature, the `createTestingModule()` will need to be chained up with the `useMocker()` method, passing a factory for your dependency mocks. This factory can take in an optional token, which is an instance token, any token which is valid for a Nest provider, and returns a mock implementation. The below is an example of creating a generic mocker using [`jest-mock`](https://www.npmjs.com/package/jest-mock) and a specific mock for `CatsService` using `jest.fn()`.
> info **Hint** A general mock factory, like `createMock` from [`@golevelup/ts-jest`](https://github.com/golevelup/nestjs/tree/master/packages/testing) can also be passed directly.
195
+
196
+
You can also retrieve these mocks out of the testing container as you normally would custom providers, `moduleRef.get(CatsService)`.
197
+
163
198
#### End-to-end testing
164
199
165
200
Unlike unit testing, which focuses on individual modules and classes, end-to-end (e2e) testing covers the interaction of classes and modules at a more aggregate level -- closer to the kind of interaction that end-users will have with the production system. As an application grows, it becomes hard to manually test the end-to-end behavior of each API endpoint. Automated end-to-end tests help us ensure that the overall behavior of the system is correct and meets project requirements. To perform e2e tests we use a similar configuration to the one we just covered in **unit testing**. In addition, Nest makes it easy to use the [Supertest](https://github.com/visionmedia/supertest) library to simulate HTTP requests.
In this example, we build on some of the concepts described earlier. In addition to the `compile()` method we used earlier, we now use the `createNestApplication()` method to instantiate a full Nest runtime environment. We save a reference to the running app in our `app` variable so we can use it to simulate HTTP requests.
Copy file name to clipboardExpand all lines: content/graphql/federation.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -136,6 +136,10 @@ import { UsersService } from './users.service'; // Not included in this example
136
136
exportclassAppModule {}
137
137
```
138
138
139
+
#### Example
140
+
141
+
A working example is available [here](https://github.com/nestjs/nest/tree/master/sample/31-graphql-federation-code-first/users-application) in code first mode and [here](https://github.com/nestjs/nest/tree/master/sample/32-graphql-federation-schema-first/users-application) in schema first mode.
142
+
139
143
#### Federated example: Posts
140
144
141
145
Our Post service serves aggregated posts via a `getPosts` query, but also extends our `User` type with `user.posts`
@@ -318,6 +322,9 @@ import { PostsService } from './posts.service'; // Not included in example
318
322
})
319
323
exportclassAppModule {}
320
324
```
325
+
#### Example
326
+
327
+
A working example is available [here](https://github.com/nestjs/nest/tree/master/sample/31-graphql-federation-code-first/posts-application) for the code first mode and [here](https://github.com/nestjs/nest/tree/master/sample/32-graphql-federation-schema-first/posts-application) for the schema first mode.
321
328
322
329
#### Federated example: Gateway
323
330
@@ -354,6 +361,10 @@ export class AppModule {}
354
361
355
362
> info **Hint** Apollo recommends that you don't rely on the service discovery in a production environment but use their [Graph Manager](https://www.apollographql.com/docs/graph-manager/federation/) instead.
356
363
364
+
#### Example
365
+
366
+
A working example is available [here](https://github.com/nestjs/nest/tree/master/sample/31-graphql-federation-code-first/gateway) for the code first mode and [here](https://github.com/nestjs/nest/tree/master/sample/32-graphql-federation-schema-first/gateway) for the schema first mode.
367
+
357
368
#### Sharing context
358
369
359
370
You can customize the requests between the gateway and federated services using a build service. This allows you to share context about the request. You can easily extend the default `RemoteGraphQLDataSource` and implement one of the hooks. Please refer to [Apollo Docs](https://www.apollographql.com/docs/apollo-server/api/apollo-gateway/#remotegraphqldatasource) on `RemoteGraphQLDataSource` for more information about the possibilities.
0 commit comments