feat(auth-dirs): revert @hasScope and @hasRole
make these field definition only again so it works for now.
the obj directives problem is more messy than i thought 🙃
This commit is contained in:
Родитель
eabfa99651
Коммит
222f932547
|
@ -1,4 +1,4 @@
|
|||
const { SchemaDirectiveVisitor } = require( 'apollo-server-express' )
|
||||
const { SchemaDirectiveVisitor, ForbiddenError } = require( 'apollo-server-express' )
|
||||
const { defaultFieldResolver } = require( 'graphql' )
|
||||
const appRoot = require( 'app-root-path' )
|
||||
const { validateServerRole } = require( `${appRoot}/modules/shared` )
|
||||
|
@ -11,14 +11,19 @@ module.exports = {
|
|||
}
|
||||
|
||||
visitFieldDefinition( field, details ) {
|
||||
this.wrapFields( details.objectType )
|
||||
// this.wrapFields( details.objectType )
|
||||
const { resolver = field.resolve || defaultFieldResolver, name } = field
|
||||
const requiredRole = this.args.role
|
||||
|
||||
field.resolve = async function ( parent, args, context, info ) {
|
||||
await validateServerRole( context, requiredRole )
|
||||
|
||||
const data = await resolver.call( this, parent, args, context, info )
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
wrapFields( objectType ) {
|
||||
// Mark the GraphQLObjectType object to avoid re-wrapping
|
||||
if ( objectType._authRoleFieldsWrapped ) return
|
||||
objectType._authRoleFieldsWrapped = true
|
||||
|
||||
const fields = objectType.getFields()
|
||||
|
||||
Object.keys( fields ).forEach( fieldName => {
|
||||
|
|
|
@ -10,18 +10,23 @@ module.exports = {
|
|||
}
|
||||
|
||||
visitFieldDefinition( field, details ) {
|
||||
this.wrapFields( details.objectType )
|
||||
// this.wrapFields( details.objectType )
|
||||
const { resolver = field.resolve || defaultFieldResolver, name } = field
|
||||
const requiredScope = this.args.scope
|
||||
|
||||
field.resolve = async function ( parent, args, context, info ) {
|
||||
const currentScopes = context.scopes
|
||||
await validateScopes( currentScopes, requiredScope )
|
||||
|
||||
const data = await resolver.call( this, parent, args, context, info )
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
wrapFields( objectType ) {
|
||||
// Mark the GraphQLObjectType object to avoid re-wrapping
|
||||
if ( objectType._authScopeFieldsWrapped ) return
|
||||
objectType._authScopeFieldsWrapped = true
|
||||
|
||||
const fields = objectType.getFields()
|
||||
|
||||
Object.keys( fields ).forEach( fieldName => {
|
||||
const field = fields[ fieldName ];
|
||||
const field = fields[ fieldName ]
|
||||
const { resolver = field.resolve || defaultFieldResolver, name } = field
|
||||
const requiredScope = this.args.scope
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче