Skip to content

Commit

Permalink
Utilize graphql-java's AstSorter and AstComparator.
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-winkelman committed Dec 6, 2023
1 parent 85fc7f1 commit 3ca6f46
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.github.tomakehurst.wiremock.http.Request
import com.github.tomakehurst.wiremock.matching.MatchResult
import com.github.tomakehurst.wiremock.matching.RequestMatcherExtension
import com.github.tomakehurst.wiremock.stubbing.SubEvent
import graphql.language.AstComparator
import graphql.language.AstSorter
import graphql.language.Document
import graphql.parser.Parser
import io.github.nilwurtz.exceptions.InvalidJsonException
Expand Down Expand Up @@ -110,9 +112,9 @@ class GraphqlBodyMatcher() : RequestMatcherExtension() {
}
val requestJson = request.bodyAsString.toJSONObject()

val isQueryMatch =
requestJson.graphqlQueryDocument().normalize().toString() == expectedRequestJson.graphqlQueryDocument()
.normalize().toString()
val isQueryMatch = AstComparator.isEqual(
requestJson.graphqlQueryDocument().sort(),
expectedRequestJson.graphqlQueryDocument().sort())
val isVariablesMatch = requestJson.graphqlVariables().similar(expectedRequestJson.graphqlVariables())

return when {
Expand Down Expand Up @@ -152,6 +154,6 @@ private fun JSONObject.graphqlVariables(): JSONObject {
return this.optJSONObject("variables") ?: JSONObject()
}

private fun Document.normalize(): Document {
return GraphqlQueryNormalizer.normalizeGraphqlDocument(this)
private fun Document.sort(): Document {
return AstSorter().sort(this);
}

This file was deleted.

This file was deleted.

0 comments on commit 3ca6f46

Please sign in to comment.