aPureBase / KGraphQL

Pure Kotlin GraphQL implementation
https://kgraphql.io
MIT License
301 stars 58 forks source link

Ktor: Multiple GraphQL Endpoints with seperate schemas #162

Closed MaaxGr closed 2 years ago

MaaxGr commented 3 years ago

I want to build a large scale app ktor with multiple graphql endpoints.

When i install the GraphQL Feature there is only the possibility to specify one endpoint

install(GraphQL) {
     endpoint = "/employeedata/graphql"
}

My first idea was to install the feautre a second time with another endpoint+schema-Handler

install(GraphQL) {
     endpoint = "/usermanagement/graphql"
}

Unfortunately i get the following exception: Exception in thread "main" io.ktor.application.DuplicateApplicationFeatureException: Conflicting application feature is already installed with the same key as KGraphQL

Is there anything i can do at the moment?

MaaxGr commented 3 years ago

Okay the only problem is the ktor feature-key: A dirty hack now is the set the feature key to something unique:

override val key = AttributeKey<GraphQL>( "KGraphQL-" + UUID.randomUUID())

I know this is probably something that can't be shipped into the library code. Another idea would be to pass the featureKey from the config but this isn't possible because the key-Variable is created before the configuration-Object is accessible.

MaaxGr commented 2 years ago

Here is another possible approach: https://github.com/aPureBase/KGraphQL/pull/193

That still works:

install(GraphQL) {
  endpoint = "/graphql1"
}

But that also works:

install(GraphQL.FeatureInstance("graphql1")) {
 endpoint = "/graphql1"
}

install(GraphQL.FeatureInstance("graphql2")) {
 endpoint = "/graphql2"
}

I have that approach in production, so it is usable, but not really fancy i have to admit^^

jeggy commented 2 years ago

@MaaxGr solution is now supported in version 0.18.0 which uses ktor version 2.x