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

Question: Is there a way to return objects on rules? #1515

Open
arantespp opened this issue Jun 11, 2023 · 0 comments
Open

Question: Is there a way to return objects on rules? #1515

arantespp opened this issue Jun 11, 2023 · 0 comments

Comments

@arantespp
Copy link

arantespp commented Jun 11, 2023

Question about GraphQL Shield

Is there a way to return objects on rules? I want to implement errors with union and return an object like this:

{
      "__typename": "NotAllowedError",
      "message": "User u-4 isn't allowed to access entity 1"
}

For example,

const ruleWithCustomObject = rule()(async (parent, args, ctx, info) => {
  return {
      "__typename": "NotAllowedError",
      "message": "User u-4 isn't allowed to access entity 1"
  }
})
 
const permissions = shield({
  Query: {
    user: ruleWithCustomObject,
  },
})

As far as I saw on the rules, they only allow the return: boolean | string | Error.

  • [ x ] I have checked other questions and found none that matches mine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant