-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix breakage when extracting "data" as the path in GraphQLResponse
Recently a change was made in b386856 that broke support for extracting the value from the response using the path "data". While users could simply use the "dataAsObject" method, there are many instances where users call extractValue with "data" as the path. Restore support for this, and add unit tests. (cherry picked from commit 163d1bc)
- Loading branch information
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
package com.netflix.graphql.dgs.client | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.CsvSource | ||
|
@@ -53,6 +54,7 @@ class GraphQLResponseTest { | |
@ParameterizedTest | ||
@CsvSource( | ||
value = [ | ||
"data, data", | ||
"foo, data.foo", | ||
"data.foo, data.foo", | ||
"datafoo, data.datafoo" | ||
|
@@ -238,4 +240,21 @@ class GraphQLResponseTest { | |
|
||
server.verify() | ||
} | ||
|
||
@Test | ||
fun testExtractValue() { | ||
val response = GraphQLResponse("""{"data": {"submitReview": {"submittedBy": "[email protected]"}}}""") | ||
val result = response.extractValue<Map<String, Any?>>("data") | ||
assertEquals(mapOf("submitReview" to mapOf("submittedBy" to "[email protected]")), result) | ||
assertEquals("[email protected]", response.extractValue("data.submitReview.submittedBy")) | ||
assertEquals("[email protected]", response.extractValue("submitReview.submittedBy")) | ||
} | ||
|
||
@Test | ||
fun testDataAsObject() { | ||
data class Response(val submitReview: Map<String, String>) | ||
val response = GraphQLResponse("""{"data": {"submitReview": {"submittedBy": "[email protected]"}}}""") | ||
val result = response.dataAsObject(Response::class.java) | ||
assertEquals(Response(submitReview = mapOf("submittedBy" to "[email protected]")), result) | ||
} | ||
} |