diff --git a/HelpTOC.json b/HelpTOC.json
index 8a3c1411..1729bad4 100644
--- a/HelpTOC.json
+++ b/HelpTOC.json
@@ -1 +1 @@
-{"entities":{"pages":{"sz3asd_2":{"id":"sz3asd_2","title":"GitHub","url":"https://github.com/apollographql/apollo-kotlin-execution","level":0,"tabIndex":0},"sz3asd_3":{"id":"sz3asd_3","title":"Kdoc","url":"https://apollographql.github.io/apollo-kotlin-execution/kdoc","level":0,"tabIndex":1},"sz3asd_4":{"id":"sz3asd_4","title":"Welcome","level":0,"pages":["getting-started","schema","scalars","execution-context","persisted-documents","ide","schema-dump"],"tabIndex":2},"getting-started":{"id":"getting-started","title":"Getting started","url":"getting-started.html","level":1,"parentId":"sz3asd_4","tabIndex":0},"schema":{"id":"schema","title":"Generating a schema","url":"schema.html","level":1,"parentId":"sz3asd_4","tabIndex":1},"scalars":{"id":"scalars","title":"Custom scalars","url":"scalars.html","level":1,"parentId":"sz3asd_4","tabIndex":2},"execution-context":{"id":"execution-context","title":"Execution context","url":"execution-context.html","level":1,"parentId":"sz3asd_4","tabIndex":3},"persisted-documents":{"id":"persisted-documents","title":"Persisted documents","url":"persisted-documents.html","level":1,"parentId":"sz3asd_4","tabIndex":4},"ide":{"id":"ide","title":"IDE","url":"ide.html","level":1,"parentId":"sz3asd_4","tabIndex":5},"schema-dump":{"id":"schema-dump","title":"Monitoring the generated schema","url":"schema-dump.html","level":1,"parentId":"sz3asd_4","tabIndex":6},"sz3asd_5":{"id":"sz3asd_5","title":"Integrations","level":0,"pages":["ktor","http4k","spring"],"tabIndex":3},"ktor":{"id":"ktor","title":"Ktor","url":"ktor.html","level":1,"parentId":"sz3asd_5","tabIndex":0},"http4k":{"id":"http4k","title":"http4k","url":"http4k.html","level":1,"parentId":"sz3asd_5","tabIndex":1},"spring":{"id":"spring","title":"Spring","url":"spring.html","level":1,"parentId":"sz3asd_5","tabIndex":2},"sz3asd_6":{"id":"sz3asd_6","title":"Apollo Federation","level":0,"pages":["federation"],"tabIndex":4},"federation":{"id":"federation","title":"Apollo Federation","url":"federation.html","level":1,"parentId":"sz3asd_6","tabIndex":0},"sz3asd_7":{"id":"sz3asd_7","title":"Apollo Usage Reporting","level":0,"pages":["usage-reporting"],"tabIndex":5},"usage-reporting":{"id":"usage-reporting","title":"Apollo Usage Reporting","url":"usage-reporting.html","level":1,"parentId":"sz3asd_7","tabIndex":0}}},"topLevelIds":["sz3asd_2","sz3asd_3","sz3asd_4","sz3asd_5","sz3asd_6","sz3asd_7"]}
\ No newline at end of file
+{"entities":{"pages":{"miiaz6_2":{"id":"miiaz6_2","title":"GitHub","url":"https://github.com/apollographql/apollo-kotlin-execution","level":0,"tabIndex":0},"miiaz6_3":{"id":"miiaz6_3","title":"Kdoc","url":"https://apollographql.github.io/apollo-kotlin-execution/kdoc","level":0,"tabIndex":1},"miiaz6_4":{"id":"miiaz6_4","title":"Welcome","level":0,"pages":["getting-started","schema","scalars","execution-context","persisted-documents","ide","schema-dump"],"tabIndex":2},"getting-started":{"id":"getting-started","title":"Getting started","url":"getting-started.html","level":1,"parentId":"miiaz6_4","tabIndex":0},"schema":{"id":"schema","title":"Generating a schema","url":"schema.html","level":1,"parentId":"miiaz6_4","tabIndex":1},"scalars":{"id":"scalars","title":"Custom scalars","url":"scalars.html","level":1,"parentId":"miiaz6_4","tabIndex":2},"execution-context":{"id":"execution-context","title":"Execution context","url":"execution-context.html","level":1,"parentId":"miiaz6_4","tabIndex":3},"persisted-documents":{"id":"persisted-documents","title":"Persisted documents","url":"persisted-documents.html","level":1,"parentId":"miiaz6_4","tabIndex":4},"ide":{"id":"ide","title":"IDE","url":"ide.html","level":1,"parentId":"miiaz6_4","tabIndex":5},"schema-dump":{"id":"schema-dump","title":"Monitoring the generated schema","url":"schema-dump.html","level":1,"parentId":"miiaz6_4","tabIndex":6},"miiaz6_5":{"id":"miiaz6_5","title":"Integrations","level":0,"pages":["ktor","http4k","spring"],"tabIndex":3},"ktor":{"id":"ktor","title":"Ktor","url":"ktor.html","level":1,"parentId":"miiaz6_5","tabIndex":0},"http4k":{"id":"http4k","title":"http4k","url":"http4k.html","level":1,"parentId":"miiaz6_5","tabIndex":1},"spring":{"id":"spring","title":"Spring","url":"spring.html","level":1,"parentId":"miiaz6_5","tabIndex":2},"miiaz6_6":{"id":"miiaz6_6","title":"Apollo Federation","level":0,"pages":["federation"],"tabIndex":4},"federation":{"id":"federation","title":"Apollo Federation","url":"federation.html","level":1,"parentId":"miiaz6_6","tabIndex":0},"miiaz6_7":{"id":"miiaz6_7","title":"Apollo Usage Reporting","level":0,"pages":["usage-reporting"],"tabIndex":5},"usage-reporting":{"id":"usage-reporting","title":"Apollo Usage Reporting","url":"usage-reporting.html","level":1,"parentId":"miiaz6_7","tabIndex":0}}},"topLevelIds":["miiaz6_2","miiaz6_3","miiaz6_4","miiaz6_5","miiaz6_6","miiaz6_7"]}
\ No newline at end of file
diff --git a/execution-context.html b/execution-context.html
index 0a95ef72..04be97c0 100644
--- a/execution-context.html
+++ b/execution-context.html
@@ -1,5 +1,5 @@
-
Execution context | Apollo Kotlin Execution Execution context Kotlin functions may define an additional ExecutionContext
parameter. This parameter is special and never exposed in GraphQL.
Kotlin
GraphQL
+}
Execution context Kotlin functions may define an additional ExecutionContext
parameter. This parameter is special and never exposed in GraphQL.
Kotlin
GraphQL
@GraphQLQuery
class Query {
fun viewer(context: ExecutionContext): User {
@@ -21,19 +21,19 @@
return user
}
}
-
+
type Query {
# this field has no arguments
viewer: user
}
-
ExecutionContext
is a typesafe map inspired by CoroutinesContext
. Define your own context by extending ExecutionContext.Element
:
+
ExecutionContext
is a typesafe map inspired by CoroutinesContext
. Define your own context by extending ExecutionContext.Element
:
class CurrentUser(val id: String) : ExecutionContext.Element {
override val key: ExecutionContext.Key<*>
get() = Key
companion object Key : ExecutionContext.Key<CurrentUser>
}
-
And pass it to ExecutableSchema.execute()
:
+
And pass it to ExecutableSchema.execute()
:
// Get the current logged-in user
val context = CurrentUser(getUserIdFromHttpHeaders())
@@ -43,7 +43,7 @@
.build(),
context
)
-
CurrentUser
is now available in Query.viewer
:
+
CurrentUser
is now available in Query.viewer
:
class Query {
fun viewer(context: ExecutionContext): User {
val id = context[CurrentUser]!!.id
diff --git a/federation.html b/federation.html
index c678b52b..18a77b86 100644
--- a/federation.html
+++ b/federation.html
@@ -1,5 +1,5 @@
-
Apollo Federation | Apollo Kotlin Execution Apollo Federation Apollo Kotlin Execution supports Apollo Federation .
To use federation, add the apollo-execution-subgraph
artifact to your project:
+}
Apollo Federation Apollo Kotlin Execution supports Apollo Federation .
To use federation, add the apollo-execution-subgraph
artifact to your project:
dependencies {
// Add the federation dependency
implementation("com.apollographql.execution:apollo-execution-subgraph:0.1.0")
}
-
The apollo-execution-subgraph
artifact contains the @GraphQLKey
annotation allowing you to define entities .
Defining entities You can define an entity key using the @GraphQLKey
annotation:
+
The apollo-execution-subgraph
artifact contains the @GraphQLKey
annotation allowing you to define entities .
Defining entities You can define an entity key using the @GraphQLKey
annotation:
class Product(
@GraphQLKey
val id: String,
val name: String
)
-
The @GraphQLKey
annotation is translated at build time into a matching federation @key
directive:
+
The @GraphQLKey
annotation is translated at build time into a matching federation @key
directive:
@key(fields: "id")
type Product {
id: String!,
name: String!
}
-
By adding the annotation on the field definition instead of the type definition, Apollo Kotlin Execution gives you more type safety.
Whenever a type containing a @GraphQLKey
field is present, Apollo Kotlin Execution adds the federation subgraph fields , _service
and _entities
:
+
By adding the annotation on the field definition instead of the type definition, Apollo Kotlin Execution gives you more type safety.
Whenever a type containing a @GraphQLKey
field is present, Apollo Kotlin Execution adds the federation subgraph fields , _service
and _entities
:
# an union containing all the federated types in the schema, constructed at build time
union _Entity = Product | ...
# coerced as a JSON object containing '__typename' and all the key fields.
@@ -44,7 +44,7 @@
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
-
Defining entity resolvers In order to support the _entities
field, federation requires a resolver that can resolve an entity from its key fields.
You can add one by defining a resolve
function on the companion object:
+
Defining entity resolvers In order to support the _entities
field, federation requires a resolver that can resolve an entity from its key fields.
You can add one by defining a resolve
function on the companion object:
class Product(
@GraphQLKey
val id: String,
@@ -61,7 +61,7 @@
Product("1", "foo"),
Product("2", "bar")
)
-
Just like regular resolvers, the entity resolvers can be suspend and/or have an ExecutionContext
parameter:
+
Just like regular resolvers, the entity resolvers can be suspend and/or have an ExecutionContext
parameter:
class Product(
@GraphQLKey
val id: String,
@@ -73,7 +73,7 @@
}
}
}
-
Tracing (ftv1) Apollo Kotlin Execution supports federated tracing (ftv1).
Ftv1 records timing information for each field and reports that information to the router through the "ftv1"
extension.
If you have a monograph, see usage reporting instead for how to send tracing information to the Apollo usage reporting endpoint.
To enable federated tracing, configure your ExecutableSchema
with a Ftv1Instrumentation
and matching Ftv1Context
:
+
Tracing (ftv1) Apollo Kotlin Execution supports federated tracing (ftv1).
Ftv1 records timing information for each field and reports that information to the router through the "ftv1"
extension.
If you have a monograph, see usage reporting instead for how to send tracing information to the Apollo usage reporting endpoint.
To enable federated tracing, configure your ExecutableSchema
with a Ftv1Instrumentation
and matching Ftv1Context
:
// Install the Ftv1Instrumentation in the executable schema
val schema = ServiceExecutableSchemaBuilder()
.addInstrumentation(Ftv1Instrumentation())
@@ -85,7 +85,7 @@
// The information is a Base64 encoded protobuf message used by the router
val ftv1 = response.extensions.get("ftv1")
-
Sending the "ftv1"
extension has some overhead and in real life scenarios, the router uses sampling to save network bandwidth.
This is done using the "apollo-federation-include-trace"
HTTP header:
+
Sending the "ftv1"
extension has some overhead and in real life scenarios, the router uses sampling to save network bandwidth.
This is done using the "apollo-federation-include-trace"
HTTP header:
val ftv1Context = if (httpHeaders.get("apollo-federation-include-trace") == "ftv1") {
// The router required tracing information for this request
Ftv1Context()
@@ -95,4 +95,4 @@
}
val response = schema.execute(request, ftv1Context)
-
Last modified: 31 October 2024
\ No newline at end of file
+
Last modified: 08 November 2024
\ No newline at end of file
diff --git a/getting-started.html b/getting-started.html
index bf2bd35c..9d8f3dd0 100644
--- a/getting-started.html
+++ b/getting-started.html
@@ -1,5 +1,5 @@
-
Getting started | Apollo Kotlin Execution Getting started Apollo Kotlin Execution is a code-first GraphQL execution library.
Apollo Kotlin Execution:
Generates a GraphQL schema from your Kotlin code: write Kotlin, get a typesafe API.
Doesn't use reflection. Use it on the JVM and enjoy ultra-fast start times. Or use it with Kotlin native. Apollo Kotlin Execution is KMP-ready!
Supports custom scalars, subscriptions, persisted queries and everything in the current GraphQL draft .
Integrates with Ktor , http4k and Spring .
Supports Apollo Federation .
Under the hood, Apollo Kotlin Execution uses KSP to generate GraphQL resolvers and types from your Kotlin code.
Gradle configuration Apollo Kotlin Execution comes with a Gradle plugin that:
Configure your Gradle build:
+}
Getting started Apollo Kotlin Execution is a code-first GraphQL execution library.
Apollo Kotlin Execution:
Generates a GraphQL schema from your Kotlin code: write Kotlin, get a typesafe API.
Doesn't use reflection. Use it on the JVM and enjoy ultra-fast start times. Or use it with Kotlin native. Apollo Kotlin Execution is KMP-ready!
Supports custom scalars, subscriptions, persisted queries and everything in the current GraphQL draft .
Integrates with Ktor , http4k and Spring .
Supports Apollo Federation .
Under the hood, Apollo Kotlin Execution uses KSP to generate GraphQL resolvers and types from your Kotlin code.
Gradle configuration Apollo Kotlin Execution comes with a Gradle plugin that:
Configure your Gradle build:
// build.gradle.kts
plugins {
// Kotlin and KSP are required
@@ -34,9 +34,9 @@
packageName = "com.example"
}
}
-
Disable KSP for tests (doc ):
+
Disable KSP for tests (doc ):
ksp.allow.all.target.configuration=false
-
Define your root query Write your root query class in a Query.kt
file:
+
Define your root query Write your root query class in a Query.kt
file:
// @GraphQLQuery is the entry point for KSP processing
@GraphQLQuery
class Query {
@@ -50,18 +50,18 @@
return "Hello $name"
}
}
-
Run the codegen:
+
Run the codegen:
./gradlew kspKotlin
# or if multiplatform
./gradlew kspCommonMainKotlinMetadata
-
Execute your query The codegen generates a com.example.ServiceExecutableSchemaBuilder
class that is the entry point to execute GraphQL requests:
+
Execute your query The codegen generates a com.example.ServiceExecutableSchemaBuilder
class that is the entry point to execute GraphQL requests:
val executableSchema = ServiceExecutableSchemaBuilder()
.build()
-
Create a GraphQL request:
+
Create a GraphQL request:
val request = GraphQLRequest.Builder()
.document("{ hello(name: \"sample\") }")
.build()
-
Execute the GraphQL request:
+
Execute the GraphQL request:
val response = executableSchema.execute(
request,
ExecutionContext.Empty
@@ -69,4 +69,4 @@
println(response.data)
// {hello=Hello sample}
-
Apollo Kotlin Execution supports objects, interfaces, unions, enum, input objects, deprecation, customizing names and descriptions and more.
See the Generating a schema page for more details.
Integrate with your favorite server library Apollo Kotlin Execution comes with integrations for popular server libraries:
See the respective documentation for how to configure a server with an ExecutableSchema
.
Last modified: 25 November 2024
\ No newline at end of file
+
Apollo Kotlin Execution supports objects, interfaces, unions, enum, input objects, deprecation, customizing names and descriptions and more.
See the Generating a schema page for more details.
Integrate with your favorite server library Apollo Kotlin Execution comes with integrations for popular server libraries:
See the respective documentation for how to configure a server with an ExecutableSchema
.
Last modified: 25 November 2024