Skip to content

ScopeAuth Plugin with Prisma - Possible to Access Nested parent Fields? #851

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

You must be logged in to vote

The data should be there, but there is no way to make it type-safe in the authScopes handler. The nested data is dependent on what was queried. Only data that is always selected is available in the types for parent, but the data should still exist on the parent object.

If you want to always load data, you can use include or select on the type:

builder.prismaObject('User', {
  include: {
    organization: {
      select: {
        id: true
      }
    }
  },
  runScopesOnType: true,
  authScopes: async (user, context) => {
    console.log(user.organization.id)
  },
})

Replies: 1 comment 4 replies

Comment options

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

@hayes
Comment options

@arimgibson
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