Skip to content

Instantly share code, notes, and snippets.

interface Query {
val film: Film?
val films: List<Film>
}
interface Mutation {
val createFilm: Film
}
interface Subscription {
{
"data": {
"film": {
"id": "0",
"title": "Amelie",
"actors": [
{
"id": "0",
"firstName": "Audrey",
"lastName": "Tautou"
// Instantiate DSL context
val context = cinemaContextOf(createKtorAdapter())
val result = context.query {
film(id = 0L) {
id()
title()
actors {
id()
firstName()
query {
film(id: 0) {
id
title
actors {
id
firstName
lastName
}
}
fun createKtorAdapter(): CinemaAdapter {
// Create Ktor http client
val client = HttpClient {
install(WebSockets)
}
// Create Jackson object mapper
val mapper = jacksonObjectMapper()
.registerModule(ParameterNamesModule(JsonCreator.Mode.PROPERTIES))
fun cinemaContextOf(adapter: CinemaAdapter): CinemaContext = CinemaContextImpl(adapter)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.github.ermadmi78</groupId>
<artifactId>kobby-maven-tutorial</artifactId>
<version>0.0.0-SNAPSHOT</version>
plugins {
kotlin("jvm")
id("io.github.ermadmi78.kobby") version "1.4.0"
}
dependencies {
// Add this dependency to enable Jackson annotation generation in DTO classes
compileOnly("com.fasterxml.jackson.core:jackson-annotations:2.12.2")
// Add this dependency to enable default Ktor adapters generation
type Query {
film(id: ID!): Film
films: [Film!]!
}
type Mutation {
createFilm(title: String!): Film!
}
type Subscription {