You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 19, 2023. It is now read-only.
Kobby generates resolver functions for all fields in root GraphQL types (Query, Mutation and Subscription). For
other GraphQL types, Kobby generates resolver functions only for fields with arguments. For example, for the Country type, Kobby generates the CinemaCountryResolver interface with one films method, but
for the Film type, it does not generate a resolver at all.
But sometimes we have to resolve fields without arguments. For example, we have to resolve the country field in
the Film type. You can ask Kobby to generate a resolver for this field using the @resolve directive. Let's modify
our schema:
Together with the resolver interfaces, Kobby generates the client DSL. If you don't need it, you can disable client
generation by means of kobby extension:
The kobby extension also provides additional settings for resolver generation:
kobby {
kotlin {
// Configuration of resolver interfaces generation
resolver {
// Is resolver interfaces generation enabled// By default `true` if `com.graphql-java-kickstart:graphql-java-tools`// artifact is in the project dependencies
enabled =null// Boolean// Is wrap subscription resolver functions result in `org.reactivestreams.Publisher`// By default `true` if `org.reactivestreams:reactive-streams`// artifact is in the project dependencies
publisherEnabled =null// Boolean// Package name for resolver interfaces relative to root package name
packageName ="resolver"// Prefix for resolver interfaces// By default is capitalized context name
prefix =null// String// Postfix for resolver interfaces
postfix ="Resolver"// Name for parent object argument// By default is de-capitalized name of parent object type
argument =null// String// If not null, Kobby will generate default implementation for// functions in resolver interfaces that looks like:// TODO("$toDoMessage")
toDoMessage =null// String
}
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
You can generate Kotlin resolver interfaces and DTO classes by GraphQL schema by means of Kobby Plugin.
Put your GraphQL schema file in the project resources with
graphqlsextension. For example, let definecinema.graphqlsschema file:Add Kobby plugin to your
build.gradle.kts, to generate Kotlin DSL (Maven plugin is also available):repositories { mavenLocal() mavenCentral() } buildscript { repositories { mavenLocal() mavenCentral() } } plugins { kotlin("jvm") version "1.5.21" id("io.github.ermadmi78.kobby") version "1.0.0" } dependencies { // Add this dependency to enable graphql-java-kickstart resolvers generation by Kobby compileOnly("com.graphql-java-kickstart:graphql-java-tools:11.0.1") // Add this dependency to wrap subscription resolver functions result in org.reactivestreams.Publisher compileOnly("org.reactivestreams:reactive-streams:1.0.3") }Run
gradle clean build, and Kobby will generate resolver interfaces and DTO classes for you:Kobby generates resolver functions for all fields in root GraphQL types (
Query,MutationandSubscription). Forother GraphQL types, Kobby generates resolver functions only for fields with arguments. For example, for the
Countrytype, Kobby generates theCinemaCountryResolverinterface with onefilmsmethod, butfor the
Filmtype, it does not generate a resolver at all.But sometimes we have to resolve fields without arguments. For example, we have to resolve the
countryfield inthe
Filmtype. You can ask Kobby to generate a resolver for this field using the@resolvedirective. Let's modifyour schema:
And Kobby will generate resolver interface for the
Filmtype:Together with the resolver interfaces, Kobby generates the client DSL. If you don't need it, you can disable client
generation by means of
kobbyextension:plugins { kotlin("jvm") version "1.5.21" id("io.github.ermadmi78.kobby") version "1.0.0" } kobby { kotlin { dto { graphQL { // Disable helper DTO classes generation enabled = false } } entity { // Disable entities generation enabled = false } } }The
kobbyextension also provides additional settings for resolver generation:kobby { kotlin { // Configuration of resolver interfaces generation resolver { // Is resolver interfaces generation enabled // By default `true` if `com.graphql-java-kickstart:graphql-java-tools` // artifact is in the project dependencies enabled = null // Boolean // Is wrap subscription resolver functions result in `org.reactivestreams.Publisher` // By default `true` if `org.reactivestreams:reactive-streams` // artifact is in the project dependencies publisherEnabled = null // Boolean // Package name for resolver interfaces relative to root package name packageName = "resolver" // Prefix for resolver interfaces // By default is capitalized context name prefix = null // String // Postfix for resolver interfaces postfix = "Resolver" // Name for parent object argument // By default is de-capitalized name of parent object type argument = null // String // If not null, Kobby will generate default implementation for // functions in resolver interfaces that looks like: // TODO("$toDoMessage") toDoMessage = null // String } } }Beta Was this translation helpful? Give feedback.
All reactions