Skip to content

Auth Scopes & relayMutationField -- Providing parent to Scope? #905

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

You must be logged in to vote

The parent of a mutation field is the "root" object (empty in most APIs, not the value returned from the resolve function. Pothos doesn't know anything about your User type, and the check would need to run before you try to delete the user (before you run the resolver).

What you can do istead is move the auth checks into your resolver.

{
  resolve: async (root, args, ctx) => {
    const user = await loadUser(args)
    await builder.runAuthScopes({
      developer: true,
      teacher: parseInt(ctx, args.input.id.id, 10),
      admin: user.organizarion_id
    })
   return deleteUser(args)
  }
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@arimgibson
Comment options

@hayes
Comment options

@hayes
Comment options

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