-
Hi! In 7 version can i use different schema for authorized/unauthorized requests? In previous version i use it over:
How can now i do this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Hello 👋 I am unsure whats the use case for serving two different GraphQL schemas vs using some authorization mechanism to limit access (directives) on the schema directly. Plugin currently doesn't support generating multiple schemas so you would either have to transform existing one or manually generate it. I believe you should (haven't tried it) be able to do it by providing some custom routing (see default routing, i.e. fun Application.graphQLModule() {
install(GraphQL) {
schema {
packages = listOf("com.example")
queries = listOf(
HelloWorldQuery()
)
}
}
routing {
route("/graphql", HttpMethod.Post) {
// plugin holds auto generated FULL schema + corresponding server config
val graphQLPlugin = this.application.plugin(GraphQL)
// you could transform the schema and generate the corresponding server but thats custom logic
handle {
// your logic from above goes here
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Are you planning to open class KtorGraphQLRequestParser to replace it over ServerConfiguration (Field var requestParser)? Otherwise, why is it marked as var? My case: |
Beta Was this translation helpful? Give feedback.
-
Yeah the request parser should be open, looks like it was missed on the Ktor side (Spring request parser is already open) -> please open up a PR :)
Personally I wouldn't use GraphQL for doing auth as IMHO that's already a solved problem with OAuth2. Instead I'd call my GraphQL server AFTER obtaining proper JWT tokens so you would only need to validate them (i.e. whether users have valid permissions/scopes) inside your server. |
Beta Was this translation helpful? Give feedback.
-
In the end I managed to solve the problem:
|
Beta Was this translation helpful? Give feedback.
In the end I managed to solve the problem: