Closed ermadmi78 closed 2 years ago
Available since version 1.4.0
To switch from context inheritance to context function:
Gradle
plugins {
id("io.github.ermadmi78.kobby") version "1.4.0"
}
kobby {
kotlin {
entity {
contextInheritanceEnabled = false
contextFunEnabled = true
}
}
}
Maven
<build>
<plugins>
<plugin>
<groupId>io.github.ermadmi78</groupId>
<artifactId>kobby-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate-kotlin</goal>
</goals>
<configuration>
<kotlin>
<entity>
<contextInheritanceEnabled>false</contextInheritanceEnabled>
<contextFunEnabled>true</contextFunEnabled>
</entity>
</kotlin>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The generated entity interface implements the context interface to provide access to GraphQL query building functionality. For example the entity interface
Film
generated by tutorial schema looks like following:As you can see, the entity interface
Film
extends the context interfaceCinemaContext
, which makes the entity an entry point for executing GraphQL queries. We can use Kotlin extension functions to create a smart API that looks like rich domain model. But the Kotlin extension functions defined in the context interface scope are available in the entity interface scope because the entity interface extends the context interface. Thus, context inheritance often leads to confusion in the customized API. To avoid such problems, we need to abandon context inheritance in the entity interface in favor of an accessor for the context.Our entity interface might look like this:
But such a change would break the backward compatibility of the entity interfaces. Let's add the following generation settings to maintain backward compatibility: