1- # Kaguya Shinomiya [ ![ ] ( https://jitpack.io/v/org.cufy/kaguya .svg )] ( https://jitpack.io/#org.cufy/kaguya )
1+ # Graphkt [ ![ ] ( https://jitpack.io/v/org.cufy/graphkt .svg )] ( https://jitpack.io/#org.cufy/graphkt )
22
33A GraphQL library based on
44[ graphql-java] ( http://github.com/graphql-java/graphql-java )
55with kotlin-friendly builders and ktor routing extensions.
66
7- > Please, Don't touch my harem 😪
8-
97### Install
108
119The main way of installing this library is
@@ -20,7 +18,7 @@ repositories {
2018
2119dependencies {
2220 // Replace TAG with the desired version
23- implementation(" org.cufy:kaguya :TAG" )
21+ implementation(" org.cufy:graphkt :TAG" )
2422}
2523```
2624
@@ -33,52 +31,79 @@ data class Entity(
3331 val name : String
3432)
3533
36- val EntityObjectType = GraphQLObjectType <Entity > {
37- name = " Entity"
38- description = " Some entity."
34+ val EntityObjectType = GraphQLObjectType <Entity >(" Entity" ) {
35+ description { " Some entity." }
3936
40- field(Entity ::name) {
41- type = GraphQLString
42- description = " The name of the entity."
37+ field(Entity ::name, GraphQLStringType ) {
38+ description { " The name of the entity." }
4339 }
4440
45- field(" nameWithCustomVar" ) {
46- type = GraphQLNonNull (GraphQLString )
47- description = " The name of the entity with the customVar in the context."
41+ field(" nameWithCustomVar" , GraphQLNullableType (GraphQLStringType )) {
42+ description { " The name of the entity with the customVar in the context." }
4843
4944 resolver {
50- it.name + graphQlContext.get( " myCustomVar" )
45+ it.name + context[ " myCustomVar" ]
5146 }
5247 }
5348}
5449
50+ val EntitiesFlow = MutableSharedFlow <Entity >()
51+
5552fun Application.configureGraphQL () {
53+ // you can choose any of these IDEs
54+ // graphiql()
55+ // sandbox()
56+ playground() // recommended
57+
5658 graphql {
57- graphiql = true
59+ engine(GraphQLJava ) {
60+ // engine-specific configuration
61+ }
5862
5963 context {
6064 put(" myCustomVar" , Math .random())
6165 }
6266
6367 schema {
6468 query {
65- description = " The root query."
69+ description { " The root query." }
70+
71+ field(" getEntityWithName" , EntityObjectType ) {
72+ description { " Get an entity instance." }
73+
74+ val nameArg = argument<String >(" name" , GraphQLStringType ) {
75+ description { " The name of the entity." }
76+ }
6677
67- field(" getEntityWithName" ) {
68- type = EntityObjectType
69- description = " Get an entity instance."
78+ get { Entity (nameArg()) }
79+ }
80+ }
81+ mutation {
82+ description { " The root mutation" }
7083
71- val nameArg = argument<String > {
72- type = GraphQLString
73- name = " name"
74- description = " The name of the entity."
84+ field(" pushEntity" , EntityObjectType ) {
85+ description { " Push an entity to subscribers" }
86+
87+ val nameArg = argument<String >(" name" , GraphQLStringType ) {
88+ description { " The name of the entity." }
7589 }
7690
77- resolver {
78- Entity (nameArg())
91+ get {
92+ val entity = Entity (nameArg())
93+ EntitiesFlow .emit(entity)
94+ entity
7995 }
8096 }
8197 }
98+ subscription {
99+ description { " The root subscription" }
100+
101+ field(" subscribeToEntities" , EntityObjectType ) {
102+ description { " Subscribe to pushed entities" }
103+
104+ getFlow { EntitiesFlow }
105+ }
106+ }
82107 }
83108 }
84109}
0 commit comments