Skip to content

Maven DSL entry point configuration

dermakov edited this page Dec 30, 2021 · 1 revision

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:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <build>
        <plugins>
            <plugin>
                <groupId>io.github.ermadmi78</groupId>
                <artifactId>kobby-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate-kotlin</goal>
                        </goals>
                        <configuration>
                            <kotlin>
                                <!-- Is root package name for generated DSL -->
                                <!-- should be relative to GraphQL schema directory -->
                                <relativePackage>true</relativePackage>

                                <!-- Root package name for generated DSL -->
                                <packageName>kobby.kotlin</packageName>

                                <!-- Output directory for generated DSL -->
                                <outputDirectory>target/generated-sources/kobby-kotlin</outputDirectory>

                                <!-- Configuration of DSL context generation (entry point to DSL) -->
                                <context>
                                    <!-- Context package name relative to root package name -->
                                    <!-- By default, is empty -->
                                    <packageName></packageName>

                                    <!-- Name of generated DSL context -->
                                    <!-- By default, is name of GraphQL schema file -->
                                    <!-- or `graphql` if there are multiple schema files -->
                                    <name>graphql</name>
                                </context>
                            </kotlin>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

The path to the context file will look like this:

outputDirectory/relativePackageName/rootPackageName/contextPackageName/contextName.kt

Output directory

Output directory is configured by means of kotlin.outputDirectory section and is target/generated-sources/kobby-kotlin by default.

Relative package name

If kotlin.relativePackage section 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:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <build>
        <plugins>
            <plugin>
                <groupId>io.github.ermadmi78</groupId>
                <artifactId>kobby-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate-kotlin</goal>
                        </goals>
                        <configuration>
                            <kotlin>
                                <relativePackage>false</relativePackage>
                            </kotlin>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Root package name

Root package name is configured by means of kotlin.packageName section and is kobby.kotlin by default. So, the corresponding subfolder is kobby/kotlin.

To make the root package name empty:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <build>
        <plugins>
            <plugin>
                <groupId>io.github.ermadmi78</groupId>
                <artifactId>kobby-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate-kotlin</goal>
                        </goals>
                        <configuration>
                            <kotlin>
                                <packageName></packageName>
                            </kotlin>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Context package name

Context package name is configured by means of kotlin.context.packageName section and is empty by default.

To configure your own context package name:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <build>
        <plugins>
            <plugin>
                <groupId>io.github.ermadmi78</groupId>
                <artifactId>kobby-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate-kotlin</goal>
                        </goals>
                        <configuration>
                            <kotlin>
                                <context>
                                    <packageName>my.context</packageName>
                                </context>
                            </kotlin>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

So, the corresponding subfolder will be my/context.

Context name

Context name is configured by means of kotlin.context.name section.

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:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <build>
        <plugins>
            <plugin>
                <groupId>io.github.ermadmi78</groupId>
                <artifactId>kobby-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate-kotlin</goal>
                        </goals>
                        <configuration>
                            <kotlin>
                                <context>
                                    <name>myContextName</name>
                                </context>
                            </kotlin>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Examples

Single schema file

The single schema file:

src/main/resources/io/github/ermadmi78/kobby/cinema/api/cinema.graphqls

by default will produce DSL entry point:

target/generated-sources/kobby-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

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:

target/generated-sources/kobby-kotlin/io/github/ermadmi78/kobby/multifile/kobby/kotlin/graphql.kt

with package name io.github.ermadmi78.kobby.multifile.kobby.kotlin.

Clone this wiki locally