https://kotlinlang.org logo
#ktor
Title
# ktor
d

Dariusz Kuc

02/14/2023, 10:59 PM
hello 👋 is there a way to update already configured routes? i.e. got a plugin that configures routes but some folks would like to add some processing around it (e.g. authentication)
a

Aleksei Tirman [JB]

02/15/2023, 12:26 PM
How exactly the plugin configures routes?
a

Aleksei Tirman [JB]

02/20/2023, 12:00 PM
With the above implementation, you can’t. You can extract your routes into a separate method with the
Route
type receiver, to give the users ability to call it in any place in the routing. Inside that method, you can acquire an instance of your
GraphQL
plugin to configure the routes using the
GraphQLConfiguration
.
d

Dariusz Kuc

02/24/2023, 8:52 PM
by any chance do you know of some example code that I could look up? somewhat confused how would I get an instance of the plugin in other places guessing you are suggesting a pattern similar to what authenticate plugin does, i.e.
Copy code
install(Authentication) {
  // configuration
}
install(Routing) {
  authenticate(<config>) {
    // route config
}
a

Aleksei Tirman [JB]

02/24/2023, 9:08 PM
Yes, exactly.
d

Dariusz Kuc

02/24/2023, 9:10 PM
how would I get access to my plugin from route though?
sticking stuff up to
ApplicationCall#attributes
? or is there some better way
a

Aleksei Tirman [JB]

02/24/2023, 9:13 PM
You can get an instance of the plugin by
call.application.plugin(<PluginClass>)
d

Dariusz Kuc

02/24/2023, 9:13 PM
👍
is there a way to ensure that routes get created by default? i.e. if someone does not install routing I'd like to autoconfigure the defaults
guess could expose it as
Copy code
install(GraphQL) {
  // config
}
install(Routing) {
  graphQLRoute() // <-- requires explicit user config
  graphiQLRoute()
}
a

Aleksei Tirman [JB]

02/24/2023, 9:16 PM
In this way you can’t ensure that.
d

Dariusz Kuc

02/24/2023, 9:16 PM
but if I don't do it this way then folks cannot configure auth stuff 😞 so guess kind of have to
thanks
a

Aleksei Tirman [JB]

02/24/2023, 9:17 PM
Generally, this can be solved by a documentation.
d

Dariusz Kuc

02/24/2023, 9:17 PM
another follow up question
I was installing
ContentNegotiation
globally by
Copy code
pipeline.install(ContentNegotiation) {
  jackson(streamRequestBody = config.server.streamingResponse) {
    apply(config.server.jacksonConfiguration)
  }
}
but this was breaking users who wanted to use different content negotiation on some other routes
someone opened up the PR that moved it to the routing block -> https://github.com/ExpediaGroup/graphql-kotlin/pull/1684
a

Aleksei Tirman [JB]

02/24/2023, 9:20 PM
Yes, you can install the
ContentNegotiation
plugin into specific routes
d

Dariusz Kuc

02/24/2023, 9:20 PM
sounds like the fix was not correct -> it should be applied per route
👍 i'll fix it up with the refactor
thanks
6 Views