Skip to main content

RequestContextService

RequestContextService

Creates new RequestContext instances.

Signature
class RequestContextService {
create(config: {
req?: Request;
apiType: ApiType;
channelOrToken?: Channel | string;
languageCode?: LanguageCode;
currencyCode?: CurrencyCode;
user?: User;
activeOrderId?: ID;
}) => Promise<RequestContext>;
fromRequest(req: Request, info?: GraphQLResolveInfo, requiredPermissions?: Permission[], session?: CachedSession) => Promise<RequestContext>;
}

create

method
v1.5.0
(config: { req?: Request; apiType: ApiType; channelOrToken?: Channel | string; languageCode?: LanguageCode; currencyCode?: CurrencyCode; user?: User; activeOrderId?: ID; }) => Promise<RequestContext>

Creates a RequestContext based on the config provided. This can be useful when interacting with services outside the request-response cycle, for example in stand-alone scripts or in worker jobs.

fromRequest

method
(req: Request, info?: GraphQLResolveInfo, requiredPermissions?: Permission[], session?: CachedSession) => Promise<RequestContext>

Creates a new RequestContext based on an Express request object. This is used internally in the API layer by the AuthGuard, and creates the RequestContext which is then passed to all resolvers & controllers.