Visability
- Dominant language
- TypeScript
- Stars
- 20.3k
- Forks
- 2.1k
- Avg merge
- 44m
- Merged PRs (30d)
- 6
Description
This issue originated at [type-graphql](https://github.com/MichalLytek/type-graphql/issues/796)
For a project i want to build a schema where some parts of the schema can be omitted based on a condition.
After some research i came across `graphql-ruby` they have this [visible](https://graphql-ruby.org/authorization/visibility.html) field which can be added.
By default everything is visible but you can hide parts of the schema by overriding its `visible` field based on some logic.
This also includes introspection, `fragments`, `__schema` and `__type(name: "SecretFeature")` which all will return `null/undefined`
an example just using `context`
```ts
new GraphQLObjectType({
name: "SecretFeature",
visible: (context) => context.user.permissions.include("read:secret"),
fields: {
secret: {
type: GraphQLString
}
}
})
```
an example using `context` & `root`
```ts
new GraphQLObjectType({
name: "DeletePostMutation",
visible: (root, context) => root.creatorId === context.user.id
fields: {
postId: {
type: GraphQLID
}
}
})
```
i also found some [pseudo-code](https://github.com/graphql/graphql-js/issues/113#issuecomment-663252167) for implementing such feature
Contributor guide
Assessment
This issue has not been assessed yet.