question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reusable rules: hasRole functionality

See original GitHub issue

I just updated to graphql-shield v2.0.6 and now I get this error on running my Node.js app:

RangeError: Maximum call stack size exceeded
    at convertRulesToMiddleware (/path-to-server/server/node_modules/graphql-shield/dist/index.js:1:1)
    at leafs.reduce (/path-to-server/server/node_modules/graphql-shield/dist/index.js:232:84)
    at Array.reduce (<anonymous>)
    at convertRulesToMiddleware (/path-to-server/server/node_modules/graphql-shield/dist/index.js:232:30)
    at leafs.reduce (/path-to-server/server/node_modules/graphql-shield/dist/index.js:232:84)
    at Array.reduce (<anonymous>)
    at convertRulesToMiddleware (/path-to-server/server/node_modules/graphql-shield/dist/index.js:232:30)
    at leafs.reduce (/path-to-server/server/node_modules/graphql-shield/dist/index.js:232:84)
    at Array.reduce (<anonymous>)
    at convertRulesToMiddleware (/path-to-server/server/node_modules/graphql-shield/dist/index.js:232:30)
    at leafs.reduce (/path-to-server/server/node_modules/graphql-shield/dist/index.js:232:84)
    at Array.reduce (<anonymous>)
    at convertRulesToMiddleware (/path-to-server/server/node_modules/graphql-shield/dist/index.js:232:30)
    at leafs.reduce (/path-to-server/server/node_modules/graphql-shield/dist/index.js:232:84)
    at Array.reduce (<anonymous>)
    at convertRulesToMiddleware (/path-to-server/server/node_modules/graphql-shield/dist/index.js:232:30)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12

github_iconTop GitHub Comments

4reactions
maticzavcommented, May 31, 2018

@dakshshah96 I have just noticed it. You are not using graphql-yoga. Because of this, you cannot use middlewares property to assign middleware to your schema. To make this work, you have to use graphql-middleware like this;

import { applyMiddleware } from 'graphql-middleware'

const schema = makeExecutableSchema({ typeDefs, resolvers })
const schemaWithPermissions = applyMiddleware(schema, permissions)

Hope this helps you out! 🙂

1reaction
dakshshah96commented, May 31, 2018

@maticzav Thank you so much for your patience.

Everything works as expected now 💯

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uses of hasRole() Methods (client and server side)
Server Side:- This is the Case where the details of current logged in users are available in the Database. we have to fetch...
Read more >
Introduction to Spring Method Security | Baeldung
In above example, the security rule hasRole('ROLE_ADMIN') will be applied to both getSystemYear and getSystemDate methods.
Read more >
Role Based Authorization With Firestore - Fireship
This function makes it easy to write rules by saying hasRole('admin') == true , as opposed to writing out the entire path for...
Read more >
Validate End User Permissions in the Application
If you need to restrict end user access to specific areas or operations in an application, you must validate their permissions.
Read more >
Redesigning Access Control for the OpenZeppelin Contracts - #13 ...
Following that model is easy to code a base RBAC contract that just records the Roles, and then segregate in different contracts the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found