Skip to content

How to run GraphQL query as ADMIN on behalf of a user? #2326

Answered by dotansimha
paulz asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @paulz !
This is a feature that you might need to implement, on top of your authentication solution. It's not built-in in Yoga, since it's not part of the GraphQL specification. In Hasura and other platforms, they've implemented this feature for tenants.

With Envelop/Yoga plugins, you should be able to intercept the request and manipulate the GraphQL execution context, this way you can check the validity of an admin token, and decide to inject/replace the context.currentUser with the user you wish to impersonate to (or, any other way you implemented your authentication on top of Yoga).

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@paulz
Comment options

Answer selected by paulz
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