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

How to set parent query argument to context when impl multi-tenant with directive #3457

Open
fearfate opened this issue Dec 25, 2024 · 0 comments

Comments

@fearfate
Copy link

What happened?

I'd like to impl a multi-tenant system in gqlgen.

preiously, i used a custom directive directive @authorize(permission: DataPermission!) on ARGUMENT_DEFINITION | INPUT_OBJECT | INPUT_FIELD_DEFINITION | FIELD_DEFINITION to apply the RBAC.

and there tree ways to impl multi-tenant

first, transport method, like to set tenant info in http header, which is simple but not fit my requirement

second,schame method with set tenant argument to every query and mutation, which is not elegant and annoying to using

thrid, schame method with a type Tenant {} as a top level node

but the thrid method can not reuse the directive for the directive can not read the tenant info, is there any way i ignored?

What did you expect?

directive @authorize(permission: DataPermission!) on ARGUMENT_DEFINITION | INPUT_OBJECT | INPUT_FIELD_DEFINITION | FIELD_DEFINITION

enum DataPermission {
    write_role
    read_role
}


type Query {
    tenant(tenantId: ID!): Tenant!
}

type Tenant {
    tenantId: ID!

    name: String

    role(id: ID! @authorize(permission: read_role)): Role!  @goField(forceResolver: true)
}

I can get tenantId in the directive @authorize

Minimal graphql.schema and models to reproduce

versions

  • go run github.com/99designs/gqlgen version? v0.17.61
  • go version? go version go1.23.4 linux/amd64
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