0.2.0 • Published 4 years ago

@2muchcoffee/nestjs-context v0.2.0

Weekly downloads
82
License
MIT
Repository
github
Last release
4 years ago

@2muchcoffee/nestjs-context

Allows you to get the request context outside of the NestJs request scope

Installation

npm install @2muchcoffee/nestjs-context --save

Usage

Import ContextModule to AppModule or CoreModule for once

import { ContextModule } from '@2muchcoffee/nestjs-context';
@Module({
  imports: [
    ...
    ContextModule,
    ...
  ]
})
export class AppModule {
}

After ContextModule import you can use Context and its static functions in your code

import { Context } from '@2muchcoffee/nestjs-context';
const {user} = Context.getHttpReq<Request>();

Note: In most cases author uses @2muchcoffee/nestjs-context to get context in custom validators. See samples for more details.

GraphQl

You should install @2muchcoffee/nestjs-gql-context in order to get the correct context on the framework usage

npm install @2muchcoffee/nestjs-gql-context --save

If you want the graphql context, you can get it using GqlContext instead of Context

import { GqlContext } from '@2muchcoffee/nestjs-gql-context';
GqlContext.getGqlContext<{req: Request}>()

Static Methods

MethodDescription
Contextimport { Context } from '@2muchcoffee/nestjs-context'
getContextReturns the current request pipeline
getHttpArgsReturns an array of arguments being passed to the handler
getHttpReqReturns a request object
getHttpResReturns a response object
getTypeReturns the current execution context type (string)
isHttpReturns true if the current execution context type is http
isGraphqlReturns true if the current execution context type is graphql
GqlContextimport { GqlContext } from '@2muchcoffee/nestjs-gql-context'; Context extends from GqlContext and has the same methods
getExecutionContextReturns the current gql execution context
getGqlRootThe previous object sent from the previous Query type
getGqlArgsArguments provided in the GraphQL query
getGqlContextA value which is provided to every resolver and holds important contextual information
getGqlInfoA value which holds field-specific information relevant to the current query

Samples

Take a look at samples in ./sample for usage examples.

0.1.0

4 years ago

0.2.0

4 years ago

0.0.1-6

4 years ago

0.0.1-5

4 years ago

0.0.1-3

4 years ago

0.0.1-4

4 years ago

0.0.1-2

4 years ago

0.0.1-1

4 years ago

0.0.1-0

4 years ago

0.0.5-0

4 years ago

7.0.16

4 years ago

7.0.15

4 years ago

7.0.14

4 years ago

0.0.4-beta.11

4 years ago

0.0.4-beta.9

4 years ago

0.0.4-beta.4

4 years ago

0.0.4-beta.6

4 years ago

0.0.4-beta.5

4 years ago

0.0.4-beta.3

4 years ago

0.0.4-beta.2

4 years ago

0.0.4-beta.0

4 years ago

0.0.4-beta.1

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago