Skip to content

Commit c7d14de

Browse files
Merge pull request #9 from lsafer-meemer/main
maintenance 2
2 parents 056f9dc + 6f9340c commit c7d14de

30 files changed

Lines changed: 537 additions & 484 deletions

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ data class Entity(
3535
)
3636

3737
val EntityObjectType: GraphQLObjectType<Entity> = GraphQLObjectType {
38-
name("Entity")
39-
description { "Some entity." }
38+
name = "Entity"
39+
description = "Some entity."
4040

4141
field(Entity::name) {
42+
description = "The name of the entity."
4243
type { GraphQLStringType }
43-
description { "The name of the entity." }
4444
}
4545

4646
field("nameWithCustomVar") {
47+
description = "The name of the entity with the customVar in the context."
4748
type { GraphQLStringType.Nullable }
48-
description { "The name of the entity with the customVar in the context." }
4949

5050
get {
5151
it.name + context["myCustomVar"]
@@ -58,8 +58,8 @@ val EntitiesFlow = MutableSharedFlow<Entity>()
5858
fun Application.configureGraphQL() {
5959
// you can choose any of these IDEs
6060
// graphiql()
61-
// sandbox()
62-
playground() // recommended
61+
// apolloSandbox()
62+
graphqlPlayground() // recommended
6363

6464
graphql {
6565
// add import org.cufy.graphkt.java.`graphql-java`
@@ -73,30 +73,30 @@ fun Application.configureGraphQL() {
7373

7474
schema {
7575
query {
76-
description { "The root query." }
76+
description = "The root query."
7777

7878
field("getEntityWithName") {
79+
description = "Get an entity instance."
7980
type { EntityObjectType }
80-
description { "Get an entity instance." }
8181

8282
val nameArg = argument<String>("name") {
83+
description = "The name of the entity."
8384
type { GraphQLStringType }
84-
description { "The name of the entity." }
8585
}
8686

8787
get { Entity(nameArg()) }
8888
}
8989
}
9090
mutation {
91-
description { "The root mutation" }
91+
description = "The root mutation"
9292

9393
field("pushEntity") {
94+
description = "Push an entity to subscribers"
9495
type { EntityObjectType }
95-
description { "Push an entity to subscribers" }
9696

9797
val nameArg = argument<String>("name") {
98+
description = "The name of the entity."
9899
type { GraphQLStringType }
99-
description { "The name of the entity." }
100100
}
101101

102102
get {
@@ -107,11 +107,11 @@ fun Application.configureGraphQL() {
107107
}
108108
}
109109
subscription {
110-
description { "The root subscription" }
110+
description = "The root subscription"
111111

112112
field("subscribeToEntities") {
113+
description = "Subscribe to pushed entities"
113114
type { EntityObjectType }
114-
description { "Subscribe to pushed entities" }
115115

116116
getFlow { EntitiesFlow }
117117
}

graphkt-core/src/commonMain/kotlin/Annotations.kt

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,6 @@
1515
*/
1616
package org.cufy.graphkt
1717

18-
/**
19-
* Marks the annotated component as internal.
20-
*
21-
* @since 2.0.0
22-
*/
23-
@RequiresOptIn(
24-
message = "This is an internal API and was not designed to be used directly",
25-
level = RequiresOptIn.Level.ERROR
26-
)
27-
annotation class InternalGraphktApi(
28-
/**
29-
* Optionally, the reason why the component was marked with this annotation.
30-
*/
31-
val reason: String = "This is an internal API and was not designed to be used directly"
32-
)
33-
3418
/**
3519
* Marks the annotated component as experimental.
3620
*
@@ -40,31 +24,4 @@ annotation class InternalGraphktApi(
4024
message = "This is an experimental API and might change at anytime",
4125
level = RequiresOptIn.Level.WARNING
4226
)
43-
annotation class ExperimentalGraphktApi(
44-
/**
45-
* Optionally, the reason why the component was marked with this annotation.
46-
*/
47-
val reason: String = "This is an experimental API and might change at anytime"
48-
)
49-
50-
/**
51-
* Marks the annotated component as advanced.
52-
*
53-
* Components marked by this annotation are meant
54-
* to be used in libraries and not application code.
55-
*
56-
* This was put to avoid users getter into stuff
57-
* that needs more reading by accident.
58-
*
59-
* @since 2.0.0
60-
*/
61-
@RequiresOptIn(
62-
message = "This API is meant to be used to extend the functionality of graphkt",
63-
level = RequiresOptIn.Level.WARNING
64-
)
65-
annotation class AdvancedGraphktApi(
66-
/**
67-
* Optionally, the reason why the component was marked with this annotation.
68-
*/
69-
val reason: String = "This API is meant to be used to extend the functionality of graphkt"
70-
)
27+
annotation class ExperimentalGraphktApi

graphkt-core/src/commonMain/kotlin/GraphQLEngine.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ import java.io.Reader
2727
* @author LSafer
2828
* @since 2.0.0
2929
*/
30+
@ExperimentalGraphktApi
3031
interface GraphQLEngineFactory {
3132
/**
3233
* Create a new engine instance.
3334
*
3435
* @param schema the engine's schema.
3536
* @since 2.0.0
3637
*/
38+
@ExperimentalGraphktApi
3739
operator fun invoke(schema: GraphQLSchema): GraphQLEngine
3840
}
3941

@@ -44,10 +46,12 @@ interface GraphQLEngineFactory {
4446
* @author LSafer
4547
* @since 2.0.0
4648
*/
49+
@ExperimentalGraphktApi
4750
interface GraphQLEngine {
4851
/**
4952
* Obtain a reader that reads the schema definition.
5053
*/
54+
@ExperimentalGraphktApi
5155
fun obtainSchemaReader(): Reader
5256

5357
/**
@@ -58,6 +62,7 @@ interface GraphQLEngine {
5862
* @param local the initial local.
5963
* @since 2.0.0
6064
*/
65+
@ExperimentalGraphktApi
6166
fun execute(
6267
request: GraphQLRequest,
6368
context: Map<Any?, Any?> = emptyMap(),
@@ -81,6 +86,7 @@ interface GraphQLElementWithEngine {
8186
/**
8287
* The engine factory.
8388
*/
89+
@ExperimentalGraphktApi
8490
val engine: GraphQLEngineFactory
8591
}
8692

@@ -99,5 +105,6 @@ interface GraphQLElementWithEngine {
99105
interface GraphQLMutableElementWithEngine
100106
: GraphQLElementWithEngine {
101107

108+
@ExperimentalGraphktApi
102109
override /* lateinit */ var engine: GraphQLEngineFactory
103110
}

graphkt-core/src/commonMain/kotlin/schema/Builtins.kt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import java.math.BigInteger
2121
//
2222

2323
private val GraphQLDeprecatedReasonArgument = GraphQLArgumentDefinition("reason") {
24+
description = "The reason for the deprecation."
2425
type { GraphQLStringType }
25-
description { "The reason for the deprecation." }
2626
}
2727

2828
/**
@@ -31,7 +31,7 @@ private val GraphQLDeprecatedReasonArgument = GraphQLArgumentDefinition("reason"
3131
* @since 2.0.0
3232
*/
3333
val GraphQLDeprecatedDirective = GraphQLDirectiveDefinition("deprecated") {
34-
description { "Marks the field, argument, input field or enum value as deprecated." }
34+
description = "Marks the field, argument, input field or enum value as deprecated."
3535
argument(GraphQLDeprecatedReasonArgument)
3636
location(GraphQLDirectiveLocation.FIELD_DEFINITION)
3737
location(GraphQLDirectiveLocation.ENUM_VALUE)
@@ -40,8 +40,8 @@ val GraphQLDeprecatedDirective = GraphQLDirectiveDefinition("deprecated") {
4040
}
4141

4242
private val GraphQLSpecifiedByUrlArgument = GraphQLArgumentDefinition("url") {
43+
description = "The URL that specifies the behaviour of this scalar."
4344
type { GraphQLStringType }
44-
description { "The URL that specifies the behaviour of this scalar." }
4545
}
4646

4747
/**
@@ -50,7 +50,7 @@ private val GraphQLSpecifiedByUrlArgument = GraphQLArgumentDefinition("url") {
5050
* @since 2.0.0
5151
*/
5252
val GraphQLSpecifiedByDirective = GraphQLDirectiveDefinition("specifiedBy") {
53-
description { "Exposes a URL that specifies the behaviour of this scalar." }
53+
description = "Exposes a URL that specifies the behaviour of this scalar."
5454
argument(GraphQLSpecifiedByUrlArgument)
5555
location(GraphQLDirectiveLocation.SCALAR)
5656
}
@@ -59,10 +59,10 @@ val GraphQLSpecifiedByDirective = GraphQLDirectiveDefinition("specifiedBy") {
5959
* Directs the executor to include this field or fragment only when the `if` argument is true.
6060
*/
6161
val GraphQLIncludeDirective = GraphQLDirectiveDefinition("include") {
62-
description { "Directs the executor to include this field or fragment only when the `if` argument is true." }
62+
description = "Directs the executor to include this field or fragment only when the `if` argument is true."
6363
argument("if") {
64+
description = "Included when true."
6465
type { GraphQLBooleanType }
65-
description { "Included when true." }
6666
}
6767
location(GraphQLDirectiveLocation.FRAGMENT_SPREAD)
6868
location(GraphQLDirectiveLocation.INLINE_FRAGMENT)
@@ -73,10 +73,10 @@ val GraphQLIncludeDirective = GraphQLDirectiveDefinition("include") {
7373
* Directs the executor to skip this field or fragment when the `if`'argument is true.
7474
*/
7575
val GraphQLSkipDirective = GraphQLDirectiveDefinition("skip") {
76-
description { "Directs the executor to skip this field or fragment when the `if`'argument is true." }
76+
description = "Directs the executor to skip this field or fragment when the `if`'argument is true."
7777
argument("if") {
78+
description = "Skipped when true."
7879
type { GraphQLBooleanType }
79-
description { "Skipped when true." }
8080
}
8181
location(GraphQLDirectiveLocation.FRAGMENT_SPREAD)
8282
location(GraphQLDirectiveLocation.INLINE_FRAGMENT)
@@ -117,7 +117,7 @@ fun GraphQLMutableElementWithDirectives.specifiedBy(url: String) {
117117
* @since 2.0.0
118118
*/
119119
val GraphQLIntType: GraphQLScalarType<Int> = GraphQLScalarType("Int") {
120-
description { "Built-in Int (32-bit)" }
120+
description = "Built-in Int (32-bit)"
121121
decode {
122122
require(it is GraphQLInteger) {
123123
"Expected GraphQLInteger but got ${it.javaClass.simpleName}"
@@ -135,7 +135,7 @@ val GraphQLIntType: GraphQLScalarType<Int> = GraphQLScalarType("Int") {
135135
* @since 2.0.0
136136
*/
137137
val GraphQLFloatType: GraphQLScalarType<Double> = GraphQLScalarType("Float") {
138-
description { "Built-in Float (64-bit)" }
138+
description = "Built-in Float (64-bit)"
139139
decode {
140140
when (it) {
141141
is GraphQLDecimal -> it.value.toDouble()
@@ -157,7 +157,7 @@ val GraphQLFloatType: GraphQLScalarType<Double> = GraphQLScalarType("Float") {
157157
* @since 2.0.0
158158
*/
159159
val GraphQLStringType: GraphQLScalarType<String> = GraphQLScalarType("String") {
160-
description { "Built-in String" }
160+
description = "Built-in String"
161161
decode {
162162
require(it is GraphQLString) {
163163
"Expected GraphQLString but got ${it.javaClass.simpleName}"
@@ -175,7 +175,7 @@ val GraphQLStringType: GraphQLScalarType<String> = GraphQLScalarType("String") {
175175
* @since 2.0.0
176176
*/
177177
val GraphQLBooleanType: GraphQLScalarType<Boolean> = GraphQLScalarType("Boolean") {
178-
description { "Built-in Boolean" }
178+
description = "Built-in Boolean"
179179
decode {
180180
require(it is GraphQLBoolean) {
181181
"Expected GraphQLBoolean but got ${it.javaClass.simpleName}"
@@ -193,7 +193,7 @@ val GraphQLBooleanType: GraphQLScalarType<Boolean> = GraphQLScalarType("Boolean"
193193
* @since 2.0.0
194194
*/
195195
val GraphQLIDType: GraphQLScalarType<String> = GraphQLScalarType("ID") {
196-
description { "Built-in ID" }
196+
description = "Built-in ID"
197197
decode {
198198
require(it is GraphQLString) {
199199
"Expected GraphQLString but got ${it.javaClass.simpleName}"
@@ -213,8 +213,8 @@ val GraphQLIDType: GraphQLScalarType<String> = GraphQLScalarType("ID") {
213213
* @since 2.0.0
214214
*/
215215
val GraphQLLongType: GraphQLScalarType<Long> = GraphQLScalarType("Long") {
216+
description = "Long"
216217
specifiedBy("https://github.com")
217-
description { "Long" }
218218
decode {
219219
require(it is GraphQLInteger) {
220220
"Expected GraphQLInteger but got ${it.javaClass.simpleName}"
@@ -232,7 +232,7 @@ val GraphQLLongType: GraphQLScalarType<Long> = GraphQLScalarType("Long") {
232232
* @since 2.0.0
233233
*/
234234
val GraphQLDecimalType: GraphQLScalarType<BigDecimal> = GraphQLScalarType("Decimal") {
235-
description { "Decimal" }
235+
description = "Decimal"
236236
decode {
237237
when (it) {
238238
is GraphQLDecimal -> it.value
@@ -253,7 +253,7 @@ val GraphQLDecimalType: GraphQLScalarType<BigDecimal> = GraphQLScalarType("Decim
253253
* @since 2.0.0
254254
*/
255255
val GraphQLIntegerType: GraphQLScalarType<BigInteger> = GraphQLScalarType("Integer") {
256-
description { "Integer" }
256+
description = "Integer"
257257
decode {
258258
require(it is GraphQLInteger) {
259259
"Expected GraphQLInteger but got ${it.javaClass.simpleName}"
@@ -270,8 +270,8 @@ val GraphQLIntegerType: GraphQLScalarType<BigInteger> = GraphQLScalarType("Integ
270270
*
271271
* @since 2.0.0
272272
*/
273-
val GraphQLVoidType = GraphQLScalarType<Unit>("Void") {
274-
description { "Void" }
273+
val GraphQLVoidType = GraphQLScalarType("Void") {
274+
description = "Void"
275275
decode { }
276276
encode { GraphQLBoolean(true) }
277277
}

graphkt-core/src/commonMain/kotlin/schema/Definitions.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ fun GraphQLDirective(
294294
*
295295
* This will replace the current definition.
296296
*/
297+
@Suppress("DeprecatedCallableAddReplaceWith")
298+
@Deprecated("replace with `this.definition = definition`")
297299
fun GraphQLMutableDirective.definition(
298300
definition: GraphQLDirectiveDefinition
299301
) {
@@ -444,6 +446,8 @@ fun GraphQLMutableDirectiveDefinition.location(
444446
/**
445447
* Set the repeatable property to the given [value].
446448
*/
449+
@Suppress("DeprecatedCallableAddReplaceWith")
450+
@Deprecated("replace with `this.repeatable = value`")
447451
fun GraphQLMutableDirectiveDefinition.repeatable(
448452
value: Boolean = true
449453
) {
@@ -828,7 +832,9 @@ fun <T : Any, M> GraphQLMutableFieldDefinition(): GraphQLMutableFieldDefinition<
828832
override val arguments = mutableListOf<GraphQLArgumentDefinition<*>>()
829833
override val onGetBlocks = mutableListOf<GraphQLGetterBlock<T, M>>()
830834
override val onGetBlockingBlocks = mutableListOf<GraphQLGetterBlockingBlock<T, M>>()
831-
override var getter: GraphQLFlowGetter<T, M> = { throw NotImplementedError("Getter of field $name was not implemented.") }
835+
override var getter: GraphQLFlowGetter<T, M> = {
836+
throw NotImplementedError("Getter of field $name was not implemented.")
837+
}
832838
}
833839
}
834840

@@ -1405,7 +1411,9 @@ fun <T : Any> GraphQLMutableInterfaceType(): GraphQLMutableInterfaceType<T> {
14051411
override val onGetBlocks = mutableListOf<GraphQLGetterBlock<T, *>>()
14061412
override val onGetBlockingBlocks = mutableListOf<GraphQLGetterBlockingBlock<T, *>>()
14071413
override val fields = mutableListOf<GraphQLFieldDefinition<T, *>>()
1408-
override var typeGetter: GraphQLTypeGetter<T> = { throw NotImplementedError("Type getter of interface $name was not implemented.") }
1414+
override var typeGetter: GraphQLTypeGetter<T> = {
1415+
throw NotImplementedError("Type getter of interface $name was not implemented.")
1416+
}
14091417
}
14101418
}
14111419

@@ -2075,7 +2083,9 @@ fun <T : Any> GraphQLMutableUnionType(): GraphQLMutableUnionType<T> {
20752083
override lateinit var name: String
20762084
override var description: String = ""
20772085
override val directives = mutableListOf<GraphQLDirective>()
2078-
override var typeGetter: GraphQLTypeGetter<T> = { throw NotImplementedError("Type getter of union $name was not implemented.") }
2086+
override var typeGetter: GraphQLTypeGetter<T> = {
2087+
throw NotImplementedError("Type getter of union $name was not implemented.")
2088+
}
20792089
override val types = mutableListOf<GraphQLObjectType<out T>>()
20802090
}
20812091
}

0 commit comments

Comments
 (0)