Skip to content

Commit 1b854fe

Browse files
committed
Migrate to official GraphQL Spring Boot Starter
1 parent 53d9afe commit 1b854fe

12 files changed

Lines changed: 95 additions & 95 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The GraphQL Client DSL code in this tutorial is generated using the [Kobby Plugi
88
1. Clone this tutorial
99
1. 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)
1010
1. 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 } }`)
1212
1. Start client: `./mvnw -pl kobby-maven-tutorial-cinema-client -am spring-boot:run`
1313
1. See queries, generated by Kobby DSL in client output
1414
1. 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)

kobby-maven-tutorial-cinema-client/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@
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>

kobby-maven-tutorial-cinema-client/src/main/kotlin/io/github/ermadmi78/kobby/cinema/client/application.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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)

kobby-maven-tutorial-cinema-server/pom.xml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@
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>
@@ -42,7 +45,7 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

kobby-maven-tutorial-cinema-server/src/main/kotlin/io/github/ermadmi78/kobby/cinema/server/resolvers/MutationResolver.kt

Lines changed: 0 additions & 22 deletions
This file was deleted.

kobby-maven-tutorial-cinema-server/src/main/kotlin/io/github/ermadmi78/kobby/cinema/server/resolvers/QueryResolver.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.

kobby-maven-tutorial-cinema-server/src/main/kotlin/io/github/ermadmi78/kobby/cinema/server/resolvers/SubscriptionResolver.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)