Skip to content

Commit

Permalink
single query in mutli requst test, and one method for mutlie serializ…
Browse files Browse the repository at this point in the history
…ation instead of two
  • Loading branch information
manymotes committed Jul 20, 2022
1 parent fb30c4b commit 03d55af
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,9 @@ class GraphQLMultiQueryRequest(
) {

fun serialize(): String {
if (requests.isEmpty()) throw AssertionError("Request must have at least one query")

if (requests.size == 1) {
return requests[0].serialize()
}

return multiQuery()
}
if (requests.isEmpty()) throw AssertionError("Request must have at least one query")

private fun multiQuery(): String {
val operationDef = OperationDefinition.newOperationDefinition()
requests[0].query.name?.let { operationDef.name(it) }
requests[0].query.getOperationType()?.let { operationDef.operation(OperationDefinition.Operation.valueOf(it.uppercase())) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,31 @@ class GraphQLMultiQueryRequestTest {
multiRequest.serialize()
}
}

@Test
fun testSerializeInputClassWithProjectionAndSingleQueriesAndAlias() {
val query = TestGraphQLQuery().apply {
input["movie"] = Movie(1234, "testMovie")
}

query.queryAlias = "alias1"

val multiRequest = GraphQLMultiQueryRequest(
listOf(
GraphQLQueryRequest(query, MovieProjection().name().movieId())
)
)

val result = multiRequest.serialize()
GraphQLQueryRequestTest.assertValidQuery(result)
Assertions.assertThat(result).isEqualTo(
"""query {
| alias1: test(movie: {movieId : 1234, name : "testMovie"}) {
| name
| movieId
| }
|}
""".trimMargin()
)
}
}

0 comments on commit 03d55af

Please sign in to comment.