Task: Add basic for graphql implements and add graphql playground and add schema and query and subscription resolver
This commit is contained in:
parent
7b4499d92f
commit
86383726af
@ -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")
|
||||||
|
12
src/main/kotlin/com/cubetiqs/graphql/demo/context/GQuery.kt
Normal file
12
src/main/kotlin/com/cubetiqs/graphql/demo/context/GQuery.kt
Normal 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 = "",
|
||||||
|
)
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
@ -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))
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
7
src/main/resources/schema.graphqls
Normal file
7
src/main/resources/schema.graphqls
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
type Query {
|
||||||
|
hello: String
|
||||||
|
}
|
||||||
|
|
||||||
|
type Subscription {
|
||||||
|
hello: Int
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user