Skip to content

4.0.0

Choose a tag to compare

@dariuszkuc dariuszkuc released this 20 Apr 02:13
· 390 commits to master since this release
4f0720b

🎉 GraphQL Kotlin 4.0.0!

Namespace Cleanup

The library structure was updated to consistently group common features into sub-directories and all the modules were updated to use a matching package structure. See our Github discussion for more details.

Some examples

com.expediagroup.graphql.annotations.* --> com.expediagroup.graphql.generator.annotations.*
com.expediagroup.graphql.federation.* --> com.expediagroup.graphql.generator.federation.*
com.expediagroup.graphql.spring.operations.* --> com.expediagroup.graphql.server.operations.*

Optional and Default Arguments

In previous versions, optional arguments, or nullable in Kotlin, were by default given null at execution time if no argument was passed in. This means if you called the following function from GraphQL without any argument the output would be "input was null"

fun print(value: String?) = "input was $value"

To support Kotlin default arguments we need to not pass anything to the Kotlin function when we invoke it, that means now that ALL nullable arguments must either:

fun defaultValue(value: String? = null) = "input was $value"
fun optionalInput(input: OptionalInput<String>): String = when (input) {
    is OptionalInput.Undefined -> "input was not specified"
    is OptionalInput.Defined<String> -> "input was ${input.value}"
}

See more details in #1126

Server Improvements

We have abstracted the common GraphQL server logic to a new graphql-kotlin-server module. This allows us to simplify the logic and greatly reduce the amount of boilerplate code needed to create a GraphQL server in any framework.

GraphQL Kotlin servers now also support batch operations. This allows your client to send a list of GraphQL operations in a single HTTP request. Stay tuned for batch query processing optimizations coming up in future releases!

Check out our Spring based reference implementation and Ktor server example to see how easy it is to create GraphQL servers using graphql-kotlin. See our updated server documentation for additional details.

GraphQL Client Rewrite

In 4.0.0, we completely rewrote our GraphQL Kotlin Client to be more generic and provide additional functionality. GraphQLClient is now a generic interface with Ktor HTTP Client and Spring WebClient reference implementations. We also abstracted away the serialization logic and now support both Jackson and kotlinx-serialization formats!

The generated data models were simplified and now are just simple data classes. Input objects, enums, and scalar definitions are now shared across operations, whereas operation-specific definitions (like objects or polymorphic types) are now generated under their own packages. Finally, query and mutation objects are now passed directly to a generic execute method which allows us to also support batch requests.

val client = GraphQLKtorClient(url = URL("http://localhost:8080/graphql"))
val firstQuery = FirstQuery(variables = FirstQuery.Variables(foo = "bar"))
val secondQuery = SecondQuery(variables = SecondQuery.Variables(foo = "baz"))

val results: List<GraphQLResponse<*>> = client.execute(listOf(firstQuery, secondQuery))

See the client documentation for additional details.

Plugin Updates

GraphQL Kotlin plugins can now be used to generate your GraphQL schema SDL artifact at build time.

import com.expediagroup.graphql.plugin.gradle.graphql

graphql {
  schema {
    packages = listOf("com.example")
  }
}

In the example above, our Gradle plugin will attempt to generate your schema artifact using graphql-kotlin-schema-generator. The schema generator will then scan specified packages, searching for classes implementing our Query, Mutation, and/or Subscription marker interfaces. You can customize the default schema generator behavior by providing custom hooks provider.

The Gradle plugin was also updated to use the Gradle Worker API to isolate the plugin classpath from the general build classpath.

See the Gradle and Maven plugin documentation for additional details.

3.x.x Support

Going forward we will only support the 3.x.x branch for critical security issues or urgent bug fixes.

Feedback

As with any open source project, we want to thank the community for using our library and providing valuable feedback and even pull requests. We will continue to support this library and use it in production at @ExpediaGroup, but the goal of the project is still to make GraphQL development easier for everyone. If you have a feature request or question, feel free to start a new discussion, create a new issue or reach out to our public Slack channel.

GitHub has the full list of contributors since we made the 4.0.0 cut.


Major Changes

Minor Changes

Patch Changes

Non-version Changes