Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nest7 new decorator syntax #269

Merged
merged 2 commits into from Apr 14, 2020
Merged

Add nest7 new decorator syntax #269

merged 2 commits into from Apr 14, 2020

Conversation

edbond88
Copy link
Contributor

@edbond88 edbond88 commented Apr 5, 2020

With old syntax nest throw error.

I tried to write as written in the documentation of Custom route decorators like this:

const request = ctx.switchToHttp().getRequest();
return request.user;

but i got request.user is undefined.

So I find the user through the getNext().req

@chaunceyau
Copy link
Contributor

chaunceyau commented Apr 5, 2020

Have you tried this? https://docs.nestjs.com/graphql/tooling#custom-decorators

export const User = createParamDecorator(
  (data: unknown, ctx: ExecutionContext) =>
    GqlExecutionContext.create(ctx).getContext().user,
);

image

@edbond88
Copy link
Contributor Author

edbond88 commented Apr 7, 2020

Does not work:

return GqlExecutionContext.create(ctx).getContext().user;

Work:

return GqlExecutionContext.create(ctx).getContext().req.user;

Honestly, I do not fully understand how it should work :)

@marcjulian
Copy link
Member

marcjulian commented Apr 14, 2020

Thanks for your fix. This PR works for me as well.

Also as you commented above this is also a valid solution:

export const UserEntity = createParamDecorator(
  (data: unknown, ctx: ExecutionContext) =>
    GqlExecutionContext.create(ctx).getContext().req.user,
);

@marcjulian marcjulian merged commit e5dfc97 into notiz-dev:master Apr 14, 2020
@chaunceyau
Copy link
Contributor

chaunceyau commented Apr 14, 2020

Yes @edbond88 - it's because of how the context is passed when the GraphQL Module (Apollo-server) was created: https://github.com/fivethree-team/nestjs-prisma-starter/blob/master/src/app.module.ts

Thanks for update @marcjulian 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants