-
Notifications
You must be signed in to change notification settings - Fork 5
Gradle DSL entry point configuration
Once the GraphQL schema files are found, Kobby can generate a client-side DSL. The entry point to the generated DSL will
be placed in the Kotlin xxx.kt file, where xxx is so-called context name. There is a set of rules for placing and
naming the context file:
kobby {
kotlin {
// Is root package name for generated DSL
// should be relative to GraphQL schema directory
relativePackage = true
// Root package name for generated DSL
packageName = "kobby.kotlin"
// Output directory for generated DSL
// org.gradle.api.file.Directory
outputDirectory = project.layout.buildDirectory
.dir("generated/sources/kobby/main/kotlin").get()
// Configuration of DSL context generation (entry point to DSL)
context {
// Context package name relative to root package name
// By default is empty
packageName = null // String
// Name of generated DSL context
// By default is name of GraphQL schema file
// or `graphql` if there are multiple schema files
name = "graphql"
}
}
}The path to the context file will look like this:
outputDirectory/relativePackageName/rootPackageName/contextPackageName/contextName.kt
Output directory is configured by means of kobby.kotlin.outputDirectory property and
is build/generated/sources/kobby/main/kotlin by default.
If kobby.kotlin.relativePackage property is true (default), then the relative package name will be calculated from
the path of schema files.
For example, for a single schema file:
src/main/resources/io/github/ermadmi78/kobby/cinema/api/cinema.graphqls
the relative package name will be io.github.ermadmi78.kobby.cinema.api and the corresponding subfolder will be
io/github/ermadmi78/kobby/cinema/api.
To calculate the relative package name, Kobby removes
the scan directory path (src/main/resources by default) from the schema folder path.
For several schema files, Kobby will calculate the common section of the path. For example, for files:
src/main/resources/io/github/ermadmi78/kobby/multifile/schema.graphqls
src/main/resources/io/github/ermadmi78/kobby/multifile/query/query.graphqls
src/main/resources/io/github/ermadmi78/kobby/multifile/mutation/mutation.graphqls
src/main/resources/io/github/ermadmi78/kobby/multifile/subscription/subscription.graphqls
the relative package name will be io.github.ermadmi78.kobby.multifile and the corresponding subfolder will
be io/github/ermadmi78/kobby/multifile.
To switch off relative package name calculation:
kobby {
kotlin {
relativePackage = false
}
}Root package name is configured by means of kobby.kotlin.packageName property and is kobby.kotlin by default. So,
the corresponding subfolder is kobby/kotlin.
To make the root package name empty:
kobby {
kotlin {
packageName = ""
}
}Context package name is configured by means of kobby.kotlin.context.packageName property and is empty by default.
To configure your own context package name:
kobby {
kotlin {
context {
packageName = "my.context"
}
}
}So, the corresponding subfolder will be my/context.
Context name is configured by means of kobby.kotlin.context.name property.
By default, if you have a single GraphQL schema file, the context name will be the de-capitalized schema file name
without the extension. For example Cinema.graphqls schema file name produces cinema context name.
If you have multiple GraphQL schema files, then the context name is graphql by default.
To configure your own context name:
kobby {
kotlin {
context {
name = "myContextName"
}
}
}The single schema file:
src/main/resources/io/github/ermadmi78/kobby/cinema/api/cinema.graphqls
by default will produce DSL entry point:
build/generated/sources/kobby/main/kotlin/io/github/ermadmi78/kobby/cinema/api/kobby/kotlin/cinema.kt
with package name io.github.ermadmi78.kobby.cinema.api.kobby.kotlin.
Several schema files:
src/main/resources/io/github/ermadmi78/kobby/multifile/schema.graphqls
src/main/resources/io/github/ermadmi78/kobby/multifile/query/query.graphqls
src/main/resources/io/github/ermadmi78/kobby/multifile/mutation/mutation.graphqls
src/main/resources/io/github/ermadmi78/kobby/multifile/subscription/subscription.graphqls
by default will produce DSL entry point:
build/generated/sources/kobby/main/kotlin/io/github/ermadmi78/kobby/multifile/kobby/kotlin/graphql.kt
with package name io.github.ermadmi78.kobby.multifile.kobby.kotlin.