Skip to content

Commit 1c76414

Browse files
committed
feat(ktor): an option to add non-standard builtin scalars
1 parent 431623b commit 1c76414

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

ktor/src/main/kotlin/Configuration.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class ConfigurationScope(
5555
*/
5656
class Configuration(
5757
val websocket: Boolean,
58+
val builtins: Boolean,
5859
val connectionInitWaitTimeout: Duration?,
5960
val engine: GraphktEngineFactory,
6061
val schemaBlock: GraphQLSchemaBuilderBlock,
@@ -80,6 +81,15 @@ class ConfigurationBuilder : WithEngine, WithDeferredBuilder {
8081
*/
8182
var websocket: Boolean = true
8283

84+
/**
85+
* True, to add all the non-standard builtin scalars as additional types.
86+
*
87+
* Standard built-in scalars are added anyway.
88+
*
89+
* @since 2.0.0
90+
*/
91+
var builtins: Boolean = true
92+
8393
/**
8494
* Websocket connection initialization timeout.
8595
*
@@ -135,6 +145,7 @@ class ConfigurationBuilder : WithEngine, WithDeferredBuilder {
135145
deferred.forEach { it() }
136146
deferred.clear()
137147
return Configuration(
148+
builtins = builtins,
138149
websocket = websocket,
139150
connectionInitWaitTimeout = connectionInitWaitTimeout,
140151
engine = engine

ktor/src/main/kotlin/Routing.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ import kotlinx.coroutines.flow.map
2323
import org.cufy.graphkt.InternalGraphktApi
2424
import org.cufy.graphkt.ktor.internal.graphqlHttp
2525
import org.cufy.graphkt.ktor.internal.graphqlWebsocket
26-
import org.cufy.graphkt.schema.GraphQLRequest
27-
import org.cufy.graphkt.schema.GraphQLResponse
28-
import org.cufy.graphkt.schema.GraphQLSchema
26+
import org.cufy.graphkt.schema.*
2927

3028
/**
3129
* Handle graphql requests to the given [path].
@@ -62,6 +60,13 @@ fun Route.graphql(
6260
/* prepare base arguments */
6361

6462
val schema = GraphQLSchema {
63+
if (configuration.builtins) {
64+
additionalType(GraphQLLongType)
65+
additionalType(GraphQLDecimalType)
66+
additionalType(GraphQLIntegerType)
67+
additionalType(GraphQLVoidType)
68+
}
69+
6570
configuration.schemaBlock(this)
6671
}
6772

0 commit comments

Comments
 (0)