Skip to content

Don't return unauthorized fields #709

Answered by hayes
BryceDalbey asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately this isn't something that can be done in GraphQL in a spec compliant way. That being said, it's something you could do outside of pothos. I'm not sure it's a good idea, but if you want to go down this road, here is an option:

  • Add an unauthorizedFields array or something to you context object
  • In your unauthorized resolver push the path from the info object into the list of unauthorized fields and return null
  • Write a plugin for you server (Envelop for yoga, apollo has their own plugin system) that loops over the collected unauthorized fields and deletes them from the response.

This pattern isn't something I would recommend, but hopefully that helps give you an idea of how it…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@BryceDalbey
Comment options

@hayes
Comment options

@BryceDalbey
Comment options

@hayes
Comment options

Answer selected by BryceDalbey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants