Skip to content

WireMock and GraphQL

WireMock Cloud

Mock your GraphQL endpoints in WireMock Cloud with instant mock data and federated supergraph. Learn more >

There is a GraphQL extension for WireMock that allows semantically matching GraphQL queries, regardless of the order of the fields in the original request. It brings powers of request matching and response templating to the GraphQL query language.

Example:

import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock.*
import io.github.nilwurtz.GraphqlBodyMatcher
fun registerGraphQLWiremock(json: String) {
WireMock(8080).register(
post(urlPathEqualTo(endPoint))
.andMatching(GraphqlBodyMatcher.extensionName, GraphqlBodyMatcher.withRequest(json))
.willReturn(
aResponse()
.withStatus(200)
)
)
}