Skip to content

Commit fe9e407

Browse files
committed
cleanup example app
1 parent 8e837e8 commit fe9e407

25 files changed

+502
-145
lines changed

integration/graalvm/ktor-graalvm-server/build.gradle.kts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import com.expediagroup.graphql.plugin.gradle.graphql
12
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
23

34
@Suppress("DSL_SCOPE_VIOLATION") // TODO: remove once KTIJ-19369 / Gradle#22797 is fixed
@@ -10,6 +11,7 @@ plugins {
1011

1112
dependencies {
1213
implementation("com.expediagroup", "graphql-kotlin-ktor-server")
14+
implementation("com.expediagroup", "graphql-kotlin-hooks-provider")
1315
implementation(libs.logback)
1416
implementation(libs.ktor.server.cio)
1517
testImplementation(libs.kotlin.test)
@@ -31,25 +33,18 @@ graalvmNative {
3133
toolchainDetection.set(false)
3234
binaries {
3335
named("main") {
34-
fallback.set(false)
3536
verbose.set(true)
36-
3737
buildArgs.add("--initialize-at-build-time=io.ktor,kotlin,ch.qos.logback,org.slf4j")
38-
buildArgs.add("--trace-object-instantiation=java.util.jar.JarFile")
39-
40-
buildArgs.add("-H:+InstallExitHandlers")
41-
buildArgs.add("-H:+ReportUnsupportedElementsAtRuntime")
4238
buildArgs.add("-H:+ReportExceptionStackTraces")
43-
44-
imageName.set("graal-server")
45-
// mainClass.set("org.test.Main")
4639
}
4740
metadataRepository {
4841
enabled.set(true)
4942
}
5043
}
5144
}
5245

53-
val graphQLGraalVmMetadata by tasks.getting(com.expediagroup.graphql.plugin.gradle.tasks.GraphQLGraalVmMetadataTask::class) {
54-
packages.set(listOf("com.expediagroup.graalvm.ktor"))
46+
graphql {
47+
graalVm {
48+
packages = listOf("com.expediagroup.graalvm.ktor")
49+
}
5550
}

integration/graalvm/ktor-graalvm-server/src/main/kotlin/com/expediagroup/graalvm/ktor/Application.kt

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2023 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.expediagroup.graalvm.ktor
218

319
import com.expediagroup.graalvm.ktor.context.CustomContextFactory
@@ -6,21 +22,22 @@ import com.expediagroup.graalvm.ktor.schema.ArgumentQuery
622
import com.expediagroup.graalvm.ktor.schema.AsyncQuery
723
import com.expediagroup.graalvm.ktor.schema.BasicMutation
824
import com.expediagroup.graalvm.ktor.schema.ContextualQuery
9-
import com.expediagroup.graalvm.ktor.schema.DataClassQuery
25+
import com.expediagroup.graalvm.ktor.schema.CustomScalarQuery
1026
import com.expediagroup.graalvm.ktor.schema.EnumQuery
1127
import com.expediagroup.graalvm.ktor.schema.ErrorQuery
12-
import com.expediagroup.graalvm.ktor.schema.ExampleInterface
13-
import com.expediagroup.graalvm.ktor.schema.ExampleUnion
14-
import com.expediagroup.graalvm.ktor.schema.FirstImpl
15-
import com.expediagroup.graalvm.ktor.schema.FirstUnionMember
28+
import com.expediagroup.graalvm.ktor.schema.IdQuery
29+
import com.expediagroup.graalvm.ktor.schema.model.ExampleInterface
30+
import com.expediagroup.graalvm.ktor.schema.model.ExampleUnion
1631
import com.expediagroup.graalvm.ktor.schema.InnerClassQuery
1732
import com.expediagroup.graalvm.ktor.schema.ListQuery
1833
import com.expediagroup.graalvm.ktor.schema.PolymorphicQuery
1934
import com.expediagroup.graalvm.ktor.schema.ScalarQuery
20-
import com.expediagroup.graalvm.ktor.schema.SecondImpl
21-
import com.expediagroup.graalvm.ktor.schema.SecondUnionMember
2235
import com.expediagroup.graalvm.ktor.schema.TypesQuery
2336
import com.expediagroup.graalvm.ktor.schema.dataloader.ExampleDataLoader
37+
import com.expediagroup.graalvm.ktor.schema.model.FirstImpl
38+
import com.expediagroup.graalvm.ktor.schema.model.FirstUnionMember
39+
import com.expediagroup.graalvm.ktor.schema.model.SecondImpl
40+
import com.expediagroup.graalvm.ktor.schema.model.SecondUnionMember
2441
import com.expediagroup.graphql.dataloader.KotlinDataLoaderRegistryFactory
2542
import com.expediagroup.graphql.server.ktor.GraphQL
2643
import com.expediagroup.graphql.server.ktor.graphQLGetRoute
@@ -41,14 +58,15 @@ fun main() {
4158
ArgumentQuery(),
4259
AsyncQuery(),
4360
ContextualQuery(),
44-
DataClassQuery(),
61+
CustomScalarQuery(),
4562
EnumQuery(),
4663
ErrorQuery(),
64+
IdQuery(),
4765
InnerClassQuery(),
66+
ListQuery(),
4867
PolymorphicQuery(),
4968
ScalarQuery(),
50-
TypesQuery(),
51-
ListQuery()
69+
TypesQuery()
5270
)
5371
mutations = listOf(
5472
BasicMutation()

integration/graalvm/ktor-graalvm-server/src/main/kotlin/com/expediagroup/graalvm/ktor/context/CustomContextFactory.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2023 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.expediagroup.graalvm.ktor.context
218

319
import com.expediagroup.graphql.generator.extensions.plus
@@ -8,6 +24,6 @@ import java.util.UUID
824

925
class CustomContextFactory : DefaultKtorGraphQLContextFactory() {
1026
override suspend fun generateContext(request: ApplicationRequest): GraphQLContext {
11-
return super.generateContext(request).plus(mapOf("custom" to UUID.randomUUID().toString()))
27+
return super.generateContext(request).plus(mapOf("custom" to (request.headers["X-Custom-Header"] ?: UUID.randomUUID().toString())))
1228
}
1329
}

integration/graalvm/ktor-graalvm-server/src/main/kotlin/com/expediagroup/graalvm/ktor/hooks/CustomHooks.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
/*
2+
* Copyright 2023 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.expediagroup.graalvm.ktor.hooks
218

319
import com.expediagroup.graphql.generator.hooks.SchemaGeneratorHooks
20+
import com.expediagroup.graphql.plugin.schema.hooks.SchemaGeneratorHooksProvider
421
import graphql.language.StringValue
522
import graphql.schema.Coercing
623
import graphql.schema.CoercingParseLiteralException
@@ -19,6 +36,10 @@ class CustomHooks : SchemaGeneratorHooks {
1936
}
2037
}
2138

39+
class CustomHooksProvider : SchemaGeneratorHooksProvider {
40+
override fun hooks(): SchemaGeneratorHooks = CustomHooks()
41+
}
42+
2243
val graphqlUUIDType: GraphQLScalarType = GraphQLScalarType.newScalar()
2344
.name("UUID")
2445
.description("A type representing a formatted java.util.UUID")
Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1+
/*
2+
* Copyright 2023 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.expediagroup.graalvm.ktor.schema
218

319
import com.expediagroup.graphql.generator.scalars.ID
420
import com.expediagroup.graphql.server.operations.Query
5-
import java.util.UUID
621

22+
/**
23+
* Queries verifying passing scalar arguments.
24+
*/
725
class ArgumentQuery : Query {
8-
fun idArg(arg: ID): ID = ID(arg.value.reversed())
9-
fun optionalIdArg(arg: ID? = null): ID? = arg?.let { ID(it.value.reversed()) }
26+
1027
fun stringArg(arg: String): String = arg.reversed()
1128
fun optionalStringArg(arg: String? = null): String? = arg?.reversed()
1229
fun intArg(arg: Int): Int = arg.inc()
@@ -15,8 +32,6 @@ class ArgumentQuery : Query {
1532
fun optionalDoubleArg(arg: Double? = null): Double? = arg?.inc()
1633
fun booleanArg(arg: Boolean): Boolean = arg.not()
1734
fun optionalBooleanArg(arg: Boolean? = null): Boolean? = arg?.not()
18-
// fun customScalarArg(arg: UUID): UUID = arg
19-
// fun optionalCustomScalarArg(arg: UUID? = null): UUID? = arg
2035
fun manyOptionalArgs(
2136
idArg: ID? = null,
2237
stringArg: String? = null,
@@ -28,13 +43,4 @@ class ArgumentQuery : Query {
2843
} else {
2944
null
3045
}
31-
// fun listArg(arg: List<String>): List<String> = arg.reversed()
32-
// fun optionalListArg(arg: List<String>? = null): List<String>? = arg?.reversed()
33-
fun objectArg(arg: SimpleType): SimpleType = arg
34-
fun optionalObjectArg(arg: SimpleType? = null): SimpleType? = arg
35-
// fun listObjectArg(arg: List<SimpleType>): String = UUID.randomUUID().toString()
36-
}
37-
38-
data class SimpleType(val id: Int, val description: String) {
39-
fun outputOnly(): String = UUID.randomUUID().toString()
4046
}

integration/graalvm/ktor-graalvm-server/src/main/kotlin/com/expediagroup/graalvm/ktor/schema/AsyncQuery.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2023 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.expediagroup.graalvm.ktor.schema
218

319
import com.expediagroup.graalvm.ktor.schema.dataloader.EXAMPLE_LOADER
@@ -9,6 +25,9 @@ import kotlinx.coroutines.delay
925
import java.util.concurrent.CompletableFuture
1026
import kotlin.random.Random
1127

28+
/**
29+
* Queries verifying async models.
30+
*/
1231
class AsyncQuery : Query {
1332
private val random: Random = Random(100)
1433

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1+
/*
2+
* Copyright 2023 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.expediagroup.graalvm.ktor.schema
218

319
import com.expediagroup.graphql.server.operations.Mutation
420

21+
/**
22+
* Example mutation.
23+
*/
524
class BasicMutation : Mutation {
625
fun mutate(arg: String): String = arg.reversed()
726
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
1+
/*
2+
* Copyright 2023 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.expediagroup.graalvm.ktor.schema
218

319
import com.expediagroup.graphql.server.operations.Query
420
import graphql.schema.DataFetchingEnvironment
521

22+
/**
23+
* Query verifying ability to retrieve contextual data.
24+
*/
625
class ContextualQuery : Query {
726
fun contextualQuery(env: DataFetchingEnvironment): String = env.graphQlContext.getOrDefault("custom", "defaultValue")
827
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2023 Expedia, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.expediagroup.graalvm.ktor.schema
18+
19+
import com.expediagroup.graphql.server.operations.Query
20+
import java.util.UUID
21+
22+
/**
23+
* Queries used to verify custom scalar functionality.
24+
*/
25+
class CustomScalarQuery : Query {
26+
fun customScalarQuery(): UUID = UUID.randomUUID()
27+
fun nullableCustomScalarQuery(): UUID? = null
28+
fun customScalarArg(arg: UUID): UUID = arg
29+
fun optionalCustomScalarArg(arg: UUID? = null): UUID? = arg
30+
}

0 commit comments

Comments
 (0)