Task: Add basic for graphql implements and add graphql playground and add schema and query and subscription resolver

This commit is contained in:
Sambo Chea 2021-08-07 10:27:34 +07:00
parent 7b4499d92f
commit 86383726af
7 changed files with 73 additions and 4 deletions

View File

@ -20,9 +20,10 @@ extra["graphqlVersion"] = "11.0.0"
dependencies { dependencies {
implementation("com.graphql-java-kickstart:graphql-spring-boot-starter:${property("graphqlVersion")}") implementation("com.graphql-java-kickstart:graphql-spring-boot-starter:${property("graphqlVersion")}")
implementation("com.graphql-java-kickstart:graphiql-spring-boot-starter:${property("graphqlVersion")}") implementation("com.graphql-java-kickstart:playground-spring-boot-starter:${property("graphqlVersion")}")
implementation("com.graphql-java-kickstart:voyager-spring-boot-starter:${property("graphqlVersion")}") implementation("com.graphql-java-kickstart:voyager-spring-boot-starter:${property("graphqlVersion")}")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-webflux") implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
@ -48,4 +49,4 @@ tasks.withType<KotlinCompile> {
tasks.withType<Test> { tasks.withType<Test> {
useJUnitPlatform() useJUnitPlatform()
} }

View File

@ -7,5 +7,5 @@ import org.springframework.boot.runApplication
class GraphqlDemoApplication class GraphqlDemoApplication
fun main(args: Array<String>) { fun main(args: Array<String>) {
runApplication<GraphqlDemoApplication>(*args) runApplication<GraphqlDemoApplication>(*args)
} }

View File

@ -0,0 +1,12 @@
package com.cubetiqs.graphql.demo.context
import org.springframework.core.annotation.AliasFor
import org.springframework.stereotype.Component
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
@Component
annotation class GQuery(
@get:AliasFor(annotation = Component::class)
val value: String = "",
)

View File

@ -0,0 +1,13 @@
package com.cubetiqs.graphql.demo.query
import com.cubetiqs.graphql.demo.context.GQuery
import graphql.kickstart.tools.GraphQLQueryResolver
import reactor.core.publisher.Mono
import java.util.concurrent.CompletableFuture
@GQuery
class HelloQuery : GraphQLQueryResolver {
fun hello(): CompletableFuture<String> {
return Mono.just("Hello Query...!").toFuture()
}
}

View File

@ -0,0 +1,15 @@
package com.cubetiqs.graphql.demo.resolver
import graphql.kickstart.tools.GraphQLSubscriptionResolver
import graphql.schema.DataFetchingEnvironment
import org.reactivestreams.Publisher
import org.springframework.stereotype.Service
import reactor.core.publisher.Flux
import java.time.Duration
@Service
class HelloSubscriptionResolver : GraphQLSubscriptionResolver {
fun hello(env: DataFetchingEnvironment): Publisher<Int> {
return Flux.range(1, 10).delayElements(Duration.ofSeconds(1))
}
}

View File

@ -1,9 +1,30 @@
server: server:
port: 8081 port: 8081
# Spring Boot
spring: spring:
datasource: datasource:
url: jdbc:postgresql://192.168.0.202:5432/graphql-demo url: jdbc:postgresql://192.168.0.202:5432/graphql-demo
username: cubetiq username: cubetiq
password: cubetiq007 password: cubetiq007
driver-class-name: org.postgresql.Driver driver-class-name: org.postgresql.Driver
# Spring Boot Actuator
management:
endpoints:
web:
exposure:
include: health,info,metrics
# GraphQL Voyager
voyager:
enabled: true
cdn:
enabled: false
# GraphQL Playground
graphql:
playground:
enabled: true
cdn:
enabled: false

View File

@ -0,0 +1,7 @@
type Query {
hello: String
}
type Subscription {
hello: Int
}