Skip to content

Commit 3f17261

Browse files
authored
examples/ktor-server: expose GraphQL Schema at /sdl (ExpediaGroup#1351)
Not having the GraphQL schema complete with directives caused me troubles in the issue ExpediaGroup#1350 In spring-server, the `/sdl` endpoint If this commit is merged, it will be exposed as well in the ktor-server example
1 parent e8e97cb commit 3f17261

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

examples/server/ktor-server/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ cd /path/to/graphql-kotlin/examples
2020
./gradlew ktor-server:run
2121
```
2222

23-
Once the app has started you can explore the example schema by opening Playground endpoint at http://localhost:8080/playground
23+
Once the app has started you can:
24+
- send GraphQL requests by opening the Playground endpoint at http://localhost:8080/playground
25+
- send GraphQL requests directly to the endpoint at http://localhost:8080/graphql
26+
- explore and interact with the example schema by opening the Playground IDE endpoint at http://localhost:8080/playground
2427

2528
#### Example query
2629

examples/server/ktor-server/src/main/kotlin/com/expediagroup/graphql/examples/server/ktor/GraphQLModule.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.expediagroup.graphql.examples.server.ktor
1818

19+
import com.expediagroup.graphql.generator.extensions.print
1920
import io.ktor.application.Application
2021
import io.ktor.application.call
2122
import io.ktor.application.install
@@ -34,6 +35,10 @@ fun Application.graphQLModule() {
3435
KtorServer().handle(this.call)
3536
}
3637

38+
get("sdl") {
39+
call.respondText(graphQLSchema.print())
40+
}
41+
3742
get("playground") {
3843
this.call.respondText(buildPlaygroundHtml("graphql", "subscriptions"), ContentType.Text.Html)
3944
}

examples/server/ktor-server/src/main/kotlin/com/expediagroup/graphql/examples/server/ktor/ktorGraphQLSchema.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ private val queries = listOf(
3939
TopLevelObject(UniversityQueryService())
4040
)
4141
private val mutations = listOf(TopLevelObject(LoginMutationService()))
42-
private val graphQLSchema = toSchema(config, queries, mutations)
42+
val graphQLSchema = toSchema(config, queries, mutations)
4343

4444
fun getGraphQLObject(): GraphQL = GraphQL.newGraphQL(graphQLSchema).build()

0 commit comments

Comments
 (0)