GraphQLIgnore annotation not respected when running GraalVM native image
simboel opened this issue · 0 comments
Library Version
Name | Version |
---|---|
kotlin | 1.9.21 |
graphql-kotlin | 7.0.2 |
ktor + CIO | 2.3.6 |
GraalVM (Community Edition) | 21 (21.0.1+12-jvmci-23.1-b19) |
Gradle | 8.4 |
Describe the bug
It seems like @GraphQLIgnore
is not respected by the schema generator when running as GraalVM native image.
Note: This problem is only true for @GraphQLIgnore
on function level.
- When using
@GraphQLIgnore
on a function parameter, it works as expected and without problems (ie.fun onlySecondParameterShouldNotBePartOfSchema(first: Int, @GraphQLIgnore second: Int) : Int = first + second
). - When using
@GraphQLIgnore
on attributes (var/val) it works as expected, too.
To Reproduce
- Create new GraphQL kotlin based project (here using ktor)
- Apply ktor specific GraalVM native image configuration (see https://ktor.io/docs/graalvm.html#prepare-for-graalvm)
- Add support for GraalVM native image (as mentioned here https://opensource.expediagroup.com/graphql-kotlin/docs/plugins/gradle-plugin-usage-graalvm)
- Create a simple query containing a function with
@GraphQLIgnore
annotation
GraphQLIgnore no respected in general
class MyQuery : Query {
fun shouldBePartOfSchema(): Boolean = true
@GraphQLIgnore
fun shouldNotBePartOfSchema(): Int = 2
}
When this is executed with a JRE the following schema is generated:
type Query {
shouldBePartOfSchema: Boolean!
}
When executed as GraalVM native image (ie. ./gradlew nativeRun
), the following incorrect schema is generated:
type Query {
shouldBePartOfSchema: Boolean!
shouldNotBePartOfSchema: Int!
}
By the way:
If the function with @GraphQLIgnore
annoation contains unsupported GraphQL types, the application will not even start as the schema generator will throw InvalidInputFieldTypeException
or TypeNotSupportedException
depending on whether it was an input parameter or return type.
Expected behavior
I would expect the schema to be identical - no matter which runtime (JRE or native image) is being used.
shouldNotBePartOfSchema
shall not be part of the schema as it is annotated with @GraphQLIgnore
.
It seems like GraalVM native image is using a different kind of schema generation method or at least comes with some limitations. It will not respect the @GraphQLIgnore
annotations.
Please either fix the schema generation for GraalVM native image based executables or describe the limitations (ie. @GraphQLIgnore
is not working with GraalVM native image).
Example Project
The following project contains an example for this bug.
- Execute
./gradlew nativeRun
for the problem - Execute
./gradlew runFatJar
for the validation with the JVM