Skip to content
A Kotlin DSL to write tests for your graphql-java schema
Kotlin
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
gradle/wrapper
src
.gitignore
README.md
build.gradle.kts
example.gradle.properties
gradlew
gradlew.bat

README.md

Kotlin GraphQL Test DSL for graphql-java

This is a kotlin DSL to easily write (integration) tests for your graphql-java application.

It is inspired by the Spring MockMVC DSL and lets you use JsonPath to quickly retrieve results from the response.

Maven Central Actions

Gradle

testImplementation("com.symbaloo:grapql-kotlin-test-dsl:1.0.4")

Maven

<dependency>
  <groupId>com.symbaloo</groupId>
  <artifactId>graphql-kotlin-test-dsl</artifactId>
  <version>1.0.4</version>
</dependency>

Example

The following code shows an example how to use this test library.

// the graphql-java schema
val schema: GraphQL = createTestSchema()
val result: ExecutionResult = graphQLTest(schema) {
    // define a query
    query(
        """
        |query Init(${"$"}echo: String) {
        |    echo(echo: ${"$"}echo)
        |    hello { hello }
        |}""".trimMargin()
    )
    // add a variable
    variable("echo", "response")
}
    // check for noErrors
    .andExpect { noErrors() }
    // create json context
    .andExpectJson {
        // go into the result with a json path
        path<String>("\$.hello.hello") {
            // quick isEqualTo check
            isEqualTo("world")
            // do something with the result
            andDo {
                assertThat(it).isEqualTo("world")
            }
        }
        // combination of `path` and `andDo`
        pathAndDo("\$.hello") { it: Map<String, Any> ->
            assertThat(it).contains("hello", "world")
        }

        // it can also return values
        val hello = pathAndDo("\$.hello") { map: Map<String, Any> ->
            map["hello"]
        }
        assertThat(hello).isEqualTo("world")
    }
    .andReturn()

License

MIT License

You can’t perform that action at this time.