graphql / graphql/graphql-js

Visability

Open
#2,943 0 comments 1 reaction 0 assignees View on GitHub
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

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.