graphql-api demo能完善auth 验证部分?
callmesoul opened this issue · comments
CallMeSoul commented
发现很多graphql很多教程都只有graphql部分,
然后auth都只有auth部分。
然后grahpql部分没问题,
auth restful部分也没问题。
但是graphql加 auth几各种问题了
bingo5 commented
graphql 的 auth 功能和 restful 的基本一致,区别如下:
Guard
@Injectable()
export class GqlAuthGuard extends AuthGuard('jwt') {
getRequest(context: ExecutionContext) {
const ctx = GqlExecutionContext.create(context);
return ctx.getContext().req;
}
}
GraphQLModule
GraphQLModule.forRoot({
......
// 将 req 传给 context
context: ({ req }) => ({ req })
}),