https://kotlinlang.org logo
#graphql-kotlin
Title
# graphql-kotlin
d

Dariusz Kuc

02/05/2023, 9:20 PM
Hello 👋 I created draft PR for adding new Ktor GraphQL plugin module -> https://github.com/ExpediaGroup/graphql-kotlin/pull/1667 Any feedback would be greatly appreciated!
👍 1
j

Jorge R

02/14/2023, 9:33 AM
Hey @Dariusz Kuc Is there any specific way to define GraphQL queries inside an authenticate("jwt") block? I already have the implementation following "Route.authenticate" approach. Thank you!
d

Dariusz Kuc

02/14/2023, 1:28 PM
Hello 👋 Can you share a link to repo with sample code? Unsure what
authenticate
block does (is it built in? Or some custom logic?)
r

rocketraman

02/14/2023, 4:31 PM
The standard ktor authentication plugin. You wrap a route in
authenticate("auth name")
and it applies the authentication configuration for "auth name". https://ktor.io/docs/authentication.html
(We use that too with our graphql-kotlin + ktor layer)
d

Dariusz Kuc

02/14/2023, 4:54 PM
👍 i'll take a look later today or tomorrow
r

rocketraman

02/14/2023, 5:04 PM
One thing our custom graphql ktor layer has is an exception handler in our call handler i.e. the wrapper around the graphql server's
execute
call. This exception handle creates a standard GraphQLResponse for unhandled exceptions -- otherwise we found unexpected errors weren't handled properly by the client side (a 3rd party project using Elm). I haven't checked the PR but would we still have access to this extension point?
Oh and we also use a custom extension of
GraphQLContextFactory
.
Our request parser has these comments that should be taken into account for parsing the request (ktor follows the RFCs strictly instead of just defaulting to UTF-8 when doing
receiveText
):
Copy code
override suspend fun parseRequest(request: ApplicationRequest): GraphQLServerRequest = try {
    withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
      // Ktor receiveText uses the rules for plain text, and the default encoding for plain text is ISO-8859-1:
      // <https://www.rfc-editor.org/rfc/rfc7231#appendix-B>
      // <https://www.rfc-editor.org/rfc/rfc8259.html#section-8.1>
      // <https://stackoverflow.com/a/49552784/430128>
      // instead -- receive the data as a stream and default to UTF-8
      val reader = request.call.receiveStream().reader(request.contentCharset() ?: Charsets.UTF_8)
      mapper.readValue(reader, GraphQLServerRequest::class.java)
    }
  } catch (e: IOException) {
    throw IOException("Unable to parse GraphQL payload.", e)
  }
d

Dariusz Kuc

02/14/2023, 10:22 PM
will start separate threads
15 Views