Skip to content

Commit

Permalink
Fix defer payload
Browse files Browse the repository at this point in the history
  • Loading branch information
gnawf committed May 14, 2024
1 parent ad72474 commit bfebddc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,18 @@ internal class NadelHydrationTransform(
DelayedIncrementalPartialResultImpl.Builder()
.incrementalItems(
listOf(
DeferPayload.newDeferredItem()
.data(results?.newValue?.value)
.path(overallField.listOfResultKeys as List<Any>?)
DeferPayload.Builder()
.data(
mapOf(
overallField.resultKey to results?.newValue?.value,
),
)
.path(
overallField.parent?.listOfResultKeys?.let {
@Suppress("USELESS_CAST") // It's not useless because Java (yay)
it as List<Any>
} ?: emptyList()
)
.errors(
instructionSequence
.filterIsInstance<NadelResultInstruction.AddError>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,9 @@ fun combineExecutionResults(result: JsonMap, incrementalResults: List<JsonMap>):
}

private fun setDeferred(result: JsonMap, path: List<Any>, data: Any) {
when (val lastPathSegment = path.last()) {
is Int -> {
val parent = result.getValueAt(path)
@Suppress("UNCHECKED_CAST")
(parent as MutableJsonMap?)?.putAll(data as JsonMap)
}
is String -> {
val parent = result.getValueAt(path.dropLast(n = 1))
@Suppress("UNCHECKED_CAST")
(parent as MutableJsonMap?)?.put(lastPathSegment, data)
}
}
val parent = result.getValueAt(path)
@Suppress("UNCHECKED_CAST")
(parent as MutableJsonMap?)?.putAll(data as JsonMap)
}

private fun JsonMap.getValueAt(path: List<Any>): Any? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ public class HydrationDeferInRenamedFieldTestSnapshot : TestSnapshot() {
| "incremental": [
| {
| "path": [
| "issueByKey",
| "assignee"
| "issueByKey"
| ],
| "data": {
| "name": "Franklin"
| "assignee": {
| "name": "Franklin"
| }
| }
| }
| ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ public class HydrationDeferInRenamedFieldUsingRenamedFieldTestSnapshot : TestSna
| "incremental": [
| {
| "path": [
| "issueByKey",
| "assigneeV2"
| "issueByKey"
| ],
| "data": {
| "name": "SPEED"
| "assigneeV2": {
| "name": "SPEED"
| }
| }
| }
| ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ public class HydrationDeferIsDisabledForRelatedIssuesTestSnapshot : TestSnapshot
| "incremental": [
| {
| "path": [
| "issueByKey",
| "assignee"
| "issueByKey"
| ],
| "data": {
| "name": "Tom"
| "assignee": {
| "name": "Tom"
| }
| }
| }
| ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ public class HydrationDeferTestSnapshot : TestSnapshot() {
| "incremental": [
| {
| "path": [
| "issue",
| "assignee"
| "issue"
| ],
| "data": {
| "name": "Franklin"
| "assignee": {
| "name": "Franklin"
| }
| }
| }
| ]
Expand Down

0 comments on commit bfebddc

Please sign in to comment.