Is your feature request related to a problem? Please describe.
Currently, almost every GraphQL resolver manually handles authentication, authorization, and input validation within the resolve function (e.g., createUser.ts, allUsers.ts). This results in significant code duplication (15-30 lines of boilerplate per file), makes security audits difficult, and increases the risk of forgetting a critical auth check in new fields.
Describe the solution you'd like
I'd like to implement a declarative approach using Pothos plugins (AuthPlugin and a validation plugin like @pothos/plugin-zod). This would move auth and validation logic out of the resolver body and into the field definition.
Benefits:
- Secure by default: Permissions are explicit and verified at the schema level.
- Cleaner code: Resolvers focus only on business logic/database operations.
- Self-documenting: Required roles and validation rules become visible via schema introspection.
Describe alternatives you've considered
- Continuing with imperative logic: High maintenance overhead and prone to human error.
- Custom wrapper functions: While possible, using native Pothos plugins is more idiomatic, type-safe, and provides better integration with the GraphQL lifecycle.
Approach to be followed (optional)
- Enable
AuthPlugin and ValidationPlugin in src/graphql/builder.ts.
- Map
ctx.currentClient roles (e.g., administrator) to named auth scopes.
- Configure global error mapping to ensure validation/auth failures still throw TalawaGraphQLError with the correct extension codes.
- Incrementally refactor existing resolvers to use these declarative options.
Additional context
This architectural shift would align the API with modern GraphQL best practices and significantly improve the developer experience for contributors.
Is your feature request related to a problem? Please describe.
Currently, almost every GraphQL resolver manually handles authentication, authorization, and input validation within the resolve function (e.g., createUser.ts, allUsers.ts). This results in significant code duplication (15-30 lines of boilerplate per file), makes security audits difficult, and increases the risk of forgetting a critical auth check in new fields.
Describe the solution you'd like
I'd like to implement a declarative approach using Pothos plugins (
AuthPluginand a validation plugin like@pothos/plugin-zod). This would move auth and validation logic out of the resolver body and into the field definition.Benefits:
Describe alternatives you've considered
Approach to be followed (optional)
AuthPluginandValidationPluginin src/graphql/builder.ts.ctx.currentClientroles (e.g.,administrator) to named auth scopes.Additional context
This architectural shift would align the API with modern GraphQL best practices and significantly improve the developer experience for contributors.