|
| 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 |
| 18 | + |
| 19 | +import com.expediagroup.graalvm.ktor.context.CustomContextFactory |
| 20 | +import com.expediagroup.graalvm.ktor.hooks.CustomHooks |
| 21 | +import com.expediagroup.graalvm.ktor.schema.ArgumentQuery |
| 22 | +import com.expediagroup.graalvm.ktor.schema.AsyncQuery |
| 23 | +import com.expediagroup.graalvm.ktor.schema.BasicMutation |
| 24 | +import com.expediagroup.graalvm.ktor.schema.ContextualQuery |
| 25 | +import com.expediagroup.graalvm.ktor.schema.CustomScalarQuery |
| 26 | +import com.expediagroup.graalvm.ktor.schema.EnumQuery |
| 27 | +import com.expediagroup.graalvm.ktor.schema.ErrorQuery |
| 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 |
| 31 | +import com.expediagroup.graalvm.ktor.schema.InnerClassQuery |
| 32 | +import com.expediagroup.graalvm.ktor.schema.ListQuery |
| 33 | +import com.expediagroup.graalvm.ktor.schema.PolymorphicQuery |
| 34 | +import com.expediagroup.graalvm.ktor.schema.ScalarQuery |
| 35 | +import com.expediagroup.graalvm.ktor.schema.TypesQuery |
| 36 | +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 |
| 41 | +import com.expediagroup.graphql.dataloader.KotlinDataLoaderRegistryFactory |
| 42 | +import com.expediagroup.graphql.server.ktor.GraphQL |
| 43 | +import com.expediagroup.graphql.server.ktor.graphQLGetRoute |
| 44 | +import com.expediagroup.graphql.server.ktor.graphQLPostRoute |
| 45 | +import com.expediagroup.graphql.server.ktor.graphQLSDLRoute |
| 46 | +import com.expediagroup.graphql.server.ktor.graphiQLRoute |
| 47 | +import io.ktor.server.application.install |
| 48 | +import io.ktor.server.cio.CIO |
| 49 | +import io.ktor.server.engine.embeddedServer |
| 50 | +import io.ktor.server.routing.routing |
| 51 | + |
| 52 | +fun main() { |
| 53 | + embeddedServer(CIO, port = 8080, host = "0.0.0.0") { |
| 54 | + install(GraphQL) { |
| 55 | + schema { |
| 56 | + packages = listOf("com.expediagroup.graalvm.ktor") |
| 57 | + queries = listOf( |
| 58 | + ArgumentQuery(), |
| 59 | + AsyncQuery(), |
| 60 | + ContextualQuery(), |
| 61 | + CustomScalarQuery(), |
| 62 | + EnumQuery(), |
| 63 | + ErrorQuery(), |
| 64 | + IdQuery(), |
| 65 | + InnerClassQuery(), |
| 66 | + ListQuery(), |
| 67 | + PolymorphicQuery(), |
| 68 | + ScalarQuery(), |
| 69 | + TypesQuery() |
| 70 | + ) |
| 71 | + mutations = listOf( |
| 72 | + BasicMutation() |
| 73 | + ) |
| 74 | + hooks = CustomHooks() |
| 75 | + typeHierarchy = mapOf( |
| 76 | + ExampleInterface::class to listOf(FirstImpl::class, SecondImpl::class), |
| 77 | + ExampleUnion::class to listOf(FirstUnionMember::class, SecondUnionMember::class) |
| 78 | + ) |
| 79 | + } |
| 80 | + engine { |
| 81 | + dataLoaderRegistryFactory = KotlinDataLoaderRegistryFactory( |
| 82 | + ExampleDataLoader |
| 83 | + ) |
| 84 | + } |
| 85 | + server { |
| 86 | + contextFactory = CustomContextFactory() |
| 87 | + } |
| 88 | + } |
| 89 | + routing { |
| 90 | + graphQLGetRoute() |
| 91 | + graphQLPostRoute() |
| 92 | + graphQLSDLRoute() |
| 93 | + graphiQLRoute() |
| 94 | + } |
| 95 | + }.start(wait = true) |
| 96 | +} |
0 commit comments