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:
izzy lyseggen 2020-08-19 15:41:42 +01:00
Родитель eabfa99651
Коммит 222f932547
2 изменённых файлов: 23 добавлений и 13 удалений

Просмотреть файл

@ -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