[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
No support for TypeGraphQL Authorization feature: https://typegraphql.ml/docs/authorization.html
It would be nice to annotate @ObjectType class fields with @Authorized() annotation, but GraphQLModule doesn't have configuration for customAuthChecker.
If GraphQL is used for public and private (admin) usage, we would like to restrict access to fields dedicated for admin.
There is no plan to support @Authorized(). You can achieve the same behavior with class-transformer + Nest guards/interceptors.
I would appreciate it if you can provide some example or clue to achieve it. I have similar issue about it. I can use UseGuards in resolver class query. But it seems like it doesn't work with @ObjectType class fields.
There is actually support for this feature with a rather easy configuration.
Create an extending interface:
import { BuildSchemaOptions } from '@nestjs/graphql/dist/external/type-graphql.types';
import { AuthChecker } from 'type-graphql';
export interface TypeGraphQLBuildSchemaOptions extends BuildSchemaOptions {
authChecker: AuthChecker<any, any>;
}
And use it in the buildSchemaOptions (these options goes directly to type-graphqls buildSchema function):
GraphQLModule.forRoot({
autoChemaFile: 'schema.gql,
buildSchemaOptions: { authChecker: () => true } as TypeGraphQLBuildSchemaOptions
});
You could also just use any but with the cost of missing typechecking
Is there any reason why this isn't included in the BuildSchemaOptions type already?
We're actively working on the docs and will provide more tutorials shortly.
Most helpful comment
I would appreciate it if you can provide some example or clue to achieve it. I have similar issue about it. I can use
UseGuardsin resolver class query. But it seems like it doesn't work with @ObjectType class fields.