Skip to content

Instantly share code, notes, and snippets.

@shrirambalakrishnan
Created October 18, 2020 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shrirambalakrishnan/7bb5297c84da0780795fd0a40c70f20e to your computer and use it in GitHub Desktop.
Save shrirambalakrishnan/7bb5297c84da0780795fd0a40c70f20e to your computer and use it in GitHub Desktop.
const { rule, shield } = require('graphql-shield')
// Rules
const isUser = rule({ cache: 'contextual' })(
async (parent, args, ctx, info) => {
let isUser = ctx.user.roles.includes('USER');
console.log(`isUser = ${isUser}`);
return isUser;
}
)
// Permissions
const permissions = shield({
CommentType: isUser,
})
module.exports = {
permissions
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment