99designs / 99designs/gqlgen

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

Open
#3,457 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
10.8k
Forks
1.3k
Avg merge
2d 36m
Merged PRs (30d)
26

Description

### 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?

```graphql
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`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.