Skip to content

Commit

Permalink
NestJS uses the class directly as the symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
holm committed Sep 21, 2021
1 parent 00316ed commit a195209
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ export class DataLoaderInterceptor implements NestInterceptor {
*/
export const Loader = createParamDecorator(
// tslint:disable-next-line: ban-types
(data: string | Function, context: ExecutionContext) => {
const name = typeof data === "string" ? data : data?.name;
if (!name) {
(data: Function, context: ExecutionContext) => {
if (!data) {
throw new InternalServerErrorException(
`Invalid name provider to @Loader ('${name}')`
`No loader provided to @Loader ('${data}')`
);
}

Expand All @@ -96,13 +95,13 @@ export const Loader = createParamDecorator(
}

const ctx = GqlExecutionContext.create(context).getContext();
if (!name || !ctx[NEST_LOADER_CONTEXT_KEY]) {
if (!ctx[NEST_LOADER_CONTEXT_KEY]) {
throw new InternalServerErrorException(
`You should provide interceptor ${DataLoaderInterceptor.name} globally with ${APP_INTERCEPTOR}`
);
}

return ctx[NEST_LOADER_CONTEXT_KEY].getLoader(name);
return ctx[NEST_LOADER_CONTEXT_KEY].getLoader(data);
}
);

Expand Down

0 comments on commit a195209

Please sign in to comment.