Skip to content

Commit b881c82

Browse files
docs: add info for gql argumentshost
1 parent 4af4725 commit b881c82

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

content/fundamentals/execution-context.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ The `ArgumentsHost` class provides methods for retrieving the arguments being pa
1515
When building generic [guards](/guards), [filters](/exception-filters), and [interceptors](/interceptors) which are meant to run across multiple application contexts, we need a way to determine the type of application that our method is currently running in. Do this with the `getType()` method of `ArgumentsHost`:
1616

1717
```typescript
18-
const type = host.getType();
19-
if (type === 'http') {
20-
// HTTP application
21-
} else if (type === 'rpc') {
22-
// Microservice
18+
if (host.getType() === 'http') {
19+
// do something that is only important in the context of regular HTTP requests (REST)
20+
} else if (host.getType() === 'rpc') {
21+
// do something that is only important in the context of Microservice requests
22+
} else if (host.getType<GqlContextType>() === 'graphql') {
23+
// do something that is only important in the context of GraphQL requests
2324
}
2425
```
2526

27+
> info **Hint** The `GqlContextType` is imported from the `@nestjs/graphql` package.
28+
2629
With the application type available, we can write more generic components, as shown below.
2730

2831
#### Host handler arguments

0 commit comments

Comments
 (0)