-
|
Hi, I'm using Kotlin and I'm trying to craft queries/mutations for my tests with the help of the How do I correctly call the I've come up with a minimal example: package com.demeter.backend.mutations
import com.demeter.generated.DgsClient
import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest
@SpringBootTest
class RecipeTests {
@Test
fun `not working`() {
val query =
DgsClient.buildQuery {
someRecipe {
id // :compileTestKotlin Error: Function invocation 'id()' expected
}
}
}
@Test
fun working() {
val query = DgsClient.buildQuery { simple } // works just fine as the 'simple' query just returns a string
}
}
schema.graphql# ...
type Query {
someRecipe: Recipe
simple: String
}
type Recipe {
id: ID!,
title: String!
}generated files by dgs-codegenpublic object DgsClient {
public fun buildQuery(_projection: QueryProjection.() -> QueryProjection): String =
GraphQLProjection.asQuery(OperationDefinition.Operation.QUERY, QueryProjection(), _projection)
public fun buildMutation(_projection: MutationProjection.() -> MutationProjection): String =
GraphQLProjection.asQuery(OperationDefinition.Operation.MUTATION, MutationProjection(),
_projection)
}public class RecipeProjection : GraphQLProjection() {
public val id: RecipeProjection
get() {
field("id")
return this
}
public val title: RecipeProjection
get() {
field("title")
return this
}
}public class RecipeProjection<PARENT extends BaseSubProjectionNode<?, ?>, ROOT extends BaseSubProjectionNode<?, ?>> extends BaseSubProjectionNode<PARENT, ROOT> {
public RecipeProjection(PARENT parent, ROOT root) {
super(parent, root, java.util.Optional.of("Recipe"));
}
public RecipeProjection<PARENT, ROOT> id() {
getFields().put("id", null);
return this;
}
public RecipeProjection<PARENT, ROOT> title() {
getFields().put("title", null);
return this;
}
}public class QueryProjection : GraphQLProjection() {
public val simple: QueryProjection
get() {
field("simple")
return this
}
public fun someRecipe(_projection: RecipeProjection.() -> RecipeProjection): QueryProjection {
field("someRecipe", RecipeProjection(), _projection)
return this
}
}build.gradle.ktsplugins {
// ...
kotlin("jvm") version "1.9.22"
id("com.netflix.dgs.codegen") version "6.1.4"
}
// ...
tasks.withType<com.netflix.graphql.dgs.codegen.gradle.GenerateJavaTask> {
generateClient = true
generateKotlinClosureProjections = true
generateKotlinNullableClasses = true
language = "kotlin"
packageName = "com.demeter.generated"
}Kind regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Turns out, that was indeed the correct usage. I needed to delete my generated folder and re-generate the files. Now, it works like a charm. Sorry for the fuss :) |
Beta Was this translation helpful? Give feedback.
Turns out, that was indeed the correct usage. I needed to delete my generated folder and re-generate the files. Now, it works like a charm. Sorry for the fuss :)