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.

Add rule in run time

See original GitHub issue

Question about GraphQL Shield

I’m interested in knowing if it’s possible to add/remove rule in run-time.

The use case is:

  • I have a list of ‘system-rules’ and a list of ‘user-rules’
  • The ‘system-rules’ are added when the server starts
  • The ‘user-rules’ are added if the user use a method addRule where he specifies a resolver (eg: query.addUser, mutation.removeUser) and chooses one rule (eg: isAdmin, isAuthenticated)

I have no problem adding the ‘system-rules’ when the server starts. But I can’t find a way to add ‘user-rules’.

Is there a way to add rules after the shield middleware is created or to add a new shield middleware in run time?

Thanks!

  • I have checked other questions and found none that matches mine.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
P4sca1commented, Apr 3, 2019

I don’t think there is an api for that, but maybe this could work:

import { applyMiddleware } from 'graphql-middleware'

// Your other code.

apolloServer.schema = applyMiddleware(schema, yourNewPermissions)

This will recreate and reassign the whole schema to the running apollo server instance. It should work with apollo-server and graphql-yoga (as it uses apollo-server unter the hood).

0reactions
stale[bot]commented, Jul 7, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Drools - Ability to define rules at runtime? - Stack Overflow
Yes, Drools is completely dynamic. You can add/remove/replaces rules at runtime. All the existing sessions are automatically updated in order to keep ...
Read more >
Adding Run Time Prompts to Business Rules
Adding Run Time Prompts to Business Rules · From the Business Rules page, click Independent. · Click · Select the business rule to...
Read more >
How to create rules at runtime - Google Groups
First, you will need to implement a couple of interfaces (rule repository and rule set) that will be used to load rules from...
Read more >
Adding rules at Runtime · Issue #43 · j-easy/easy-rules - GitHub
Hi,. If I understood correctly, it is only possible to modify certain rules at runtime (like the example on changing the adult age)....
Read more >
Runtime Fields in Detection Rule - Elastic Discuss
Hello, I created a runtime field which I need to use in a detection rule, but I get no alerts. For the detection...
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