File tree Expand file tree Collapse file tree
kobby-maven-tutorial-cinema-client
src/main/kotlin/io/github/ermadmi78/kobby/cinema/client
kobby-maven-tutorial-cinema-server
kotlin/io/github/ermadmi78/kobby/cinema/server Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ The GraphQL Client DSL code in this tutorial is generated using the [Kobby Plugi
881 . Clone this tutorial
991 . See GraphQL schema [ here] ( https://github.com/ermadmi78/kobby-maven-tutorial/blob/main/kobby-maven-tutorial-cinema-api/src/main/resources/io/github/ermadmi78/kobby/cinema/api/cinema.graphqls )
10101 . Start server: ` ./mvnw -pl kobby-maven-tutorial-cinema-server -am spring-boot:run `
11- 1 . Try to execute GraphQL queries in [ console] ( http://localhost:8080/playground ) (for example ` query { films { id title } } ` )
11+ 1 . Try to execute GraphQL queries in [ console] ( http://localhost:8080/graphiql ) (for example ` query { films { id title } } ` )
12121 . Start client: ` ./mvnw -pl kobby-maven-tutorial-cinema-client -am spring-boot:run `
13131 . See queries, generated by Kobby DSL in client output
14141 . See client source code [ here] ( https://github.com/ermadmi78/kobby-maven-tutorial/blob/main/kobby-maven-tutorial-cinema-client/src/main/kotlin/io/github/ermadmi78/kobby/cinema/client/application.kt )
Original file line number Diff line number Diff line change 4545 <artifactId >ktor-client-cio-jvm</artifactId >
4646 <version >${ktor.version} </version >
4747 </dependency >
48- <dependency >
49- <groupId >io.ktor</groupId >
50- <artifactId >ktor-client-jackson</artifactId >
51- <version >${ktor.version} </version >
52- </dependency >
5348 <dependency >
5449 <groupId >io.ktor</groupId >
5550 <artifactId >ktor-client-websockets-jvm</artifactId >
Original file line number Diff line number Diff line change @@ -228,7 +228,7 @@ class Application : CommandLineRunner {
228228 return CinemaCompositeKtorAdapter (
229229 client,
230230 " http://localhost:8080/graphql" ,
231- " ws://localhost:8080/subscriptions " ,
231+ " ws://localhost:8080/graphql " ,
232232 object : CinemaMapper {
233233 override fun serialize (value : Any ): String =
234234 mapper.writeValueAsString(value)
Original file line number Diff line number Diff line change 1818 <version >${project.version} </version >
1919 </dependency >
2020
21+
2122 <dependency >
22- <groupId >com.graphql-java-kickstart</groupId >
23- <artifactId >graphql-spring-boot-starter</artifactId >
24- <version >${graphql.java.kickstart.version} </version >
23+ <groupId >org.springframework.boot</groupId >
24+ <artifactId >spring-boot-starter-graphql</artifactId >
2525 </dependency >
26-
2726 <dependency >
2827 <groupId >org.springframework.boot</groupId >
2928 <artifactId >spring-boot-starter-webflux</artifactId >
3029 </dependency >
30+ <dependency >
31+ <groupId >org.springframework.data</groupId >
32+ <artifactId >spring-data-commons</artifactId >
33+ </dependency >
3134
3235 <dependency >
3336 <groupId >com.fasterxml.jackson.module</groupId >
4245 </dependency >
4346 <dependency >
4447 <groupId >org.jetbrains.kotlinx</groupId >
45- <artifactId >kotlinx-coroutines-reactive </artifactId >
48+ <artifactId >kotlinx-coroutines-reactor </artifactId >
4649 <version >${kotlinx.coroutines.version} </version >
4750 </dependency >
4851 </dependencies >
Original file line number Diff line number Diff line change 1+ package io.github.ermadmi78.kobby.cinema.server.controller
2+
3+ import io.github.ermadmi78.kobby.cinema.api.kobby.kotlin.dto.FilmDto
4+ import io.github.ermadmi78.kobby.cinema.server.dao.CinemaDao
5+ import io.github.ermadmi78.kobby.cinema.server.eventbus.EventBus
6+ import org.springframework.graphql.data.method.annotation.Argument
7+ import org.springframework.graphql.data.method.annotation.SchemaMapping
8+ import org.springframework.stereotype.Controller
9+
10+ /* *
11+ * Created on 16.10.2021
12+ *
13+ * @author Dmitry Ermakov (ermadmi78@gmail.com)
14+ */
15+ @Controller
16+ @SchemaMapping(typeName = " Mutation" )
17+ class MutationController (
18+ private val cinemaDao : CinemaDao ,
19+ private val eventBus : EventBus
20+ ) {
21+ @SchemaMapping
22+ suspend fun createFilm (@Argument title : String ): FilmDto = cinemaDao.createFilm(title).also {
23+ eventBus.fireFilmCreated(it)
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ package io.github.ermadmi78.kobby.cinema.server.controller
2+
3+ import io.github.ermadmi78.kobby.cinema.api.kobby.kotlin.dto.FilmDto
4+ import io.github.ermadmi78.kobby.cinema.server.dao.CinemaDao
5+ import org.springframework.graphql.data.method.annotation.Argument
6+ import org.springframework.graphql.data.method.annotation.SchemaMapping
7+ import org.springframework.stereotype.Controller
8+
9+ /* *
10+ * Created on 16.10.2021
11+ *
12+ * @author Dmitry Ermakov (ermadmi78@gmail.com)
13+ */
14+ @Controller
15+ @SchemaMapping(typeName = " Query" )
16+ class QueryController (
17+ private val cinemaDao : CinemaDao
18+ ) {
19+ @SchemaMapping
20+ suspend fun film (@Argument id : Long ): FilmDto ? = cinemaDao.findFilm(id)
21+
22+ @SchemaMapping
23+ suspend fun films (): List <FilmDto > = cinemaDao.findFilms()
24+ }
Original file line number Diff line number Diff line change 1+ package io.github.ermadmi78.kobby.cinema.server.controller
2+
3+ import io.github.ermadmi78.kobby.cinema.api.kobby.kotlin.dto.FilmDto
4+ import io.github.ermadmi78.kobby.cinema.server.eventbus.EventBus
5+ import kotlinx.coroutines.reactor.asFlux
6+ import org.springframework.graphql.data.method.annotation.SchemaMapping
7+ import org.springframework.stereotype.Controller
8+ import reactor.core.publisher.Flux
9+
10+ /* *
11+ * Created on 16.10.2021
12+ *
13+ * @author Dmitry Ermakov (ermadmi78@gmail.com)
14+ */
15+ @Controller
16+ @SchemaMapping(typeName = " Subscription" )
17+ class SubscriptionController (
18+ private val eventBus : EventBus
19+ ) {
20+ @SchemaMapping
21+ suspend fun filmCreated (): Flux <FilmDto > = eventBus.filmCreatedFlow().asFlux()
22+ }
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments