This repository has been archived by the owner on May 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from aerogear/directives-spike
feat: initial empty hasRole implementation
- Loading branch information
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const { SchemaDirectiveVisitor } = require('graphql-tools') | ||
const { defaultFieldResolver } = require('graphql') | ||
const { log } = require('../util/logger') | ||
|
||
class HasRoleDirective extends SchemaDirectiveVisitor { | ||
visitFieldDefinition (field) { | ||
const { resolve = defaultFieldResolver } = field | ||
const { role } = this.args | ||
field.resolve = async function (root, args, context, info) { | ||
log.info('checking has role directive', role) | ||
log.info('Printing user', context.request.session) | ||
// TODO if (context.request.kauth.grant.access_token.hasRealmRole(role)) | ||
// Return appropriate error if this is false | ||
const result = await resolve.apply(this, [root, args, context, info]) | ||
return result | ||
} | ||
} | ||
} | ||
|
||
module.exports = HasRoleDirective |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters