Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning custom value from rule #436

Open
dai4 opened this issue Jul 12, 2019 · 2 comments
Open

Returning custom value from rule #436

dai4 opened this issue Jul 12, 2019 · 2 comments
Labels
kind/feature A request for a new feature.

Comments

@dai4
Copy link

dai4 commented Jul 12, 2019

Question about GraphQL Shield

Is it possible to return a custom value when a rule fails? For example, I have:

type Entity {
  primaryImage: Image
  images: [Image]
}

const Permissions = {
  Entity: {
    primaryImage: isAllowed,
    images: isAllowed
  }
};

I would like the images to return [] rather than null.

@open-collective-bot
Copy link

Hey @dai4 👋,

Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our Open Collective and consider backing us.

https://opencollective.com/graphql-shield

PS.: We offer priority support for all backers. Don't forget to add priority label when you start backing us 😄

@maticzav
Copy link
Owner

@dai4 thank you for opening the issue. Currently, I hold a strong opinion of the effects in graphql-shield. One of the primary concerns while building it was making sure no data would lack due to mistakes to secure smooth sailing while developing the permission layer. Because of that, you cannot alter the return value of the business logic functions (i.e. the underlying function) using rules.

Despite my opinion, I see a growing number of requests for such functionality. I believe I'll introduce it with a rule named effect in the upcoming version of graphql-shield as it requires a complete rewrite of the core.

@maticzav maticzav added the kind/feature A request for a new feature. label Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature A request for a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants