@@ -99,16 +99,18 @@ private class ValueOf(private val present: Step?) : Step {
9999private val Unwrapped .Wrapper .isFuture
100100 get() = Future ::class .java.isAssignableFrom(wrapper.type) || CompletionStage ::class .java.isAssignableFrom(wrapper.type)
101101
102- private fun steps (unwrapped : List <Unwrapped >, awaits : Awaitable , peels : Awaitable ): Step ? =
103- unwrapped.foldRightIndexed(null as Step ? ) { i, it, next ->
104- when (it) {
105- is Unwrapped .Wrapper -> if (it.isFuture) Await (it.wrapper, awaits, next) else Peel (it.wrapper, peels, next)
106- Unwrapped .Data -> next?.let (::DataOf )
107- // graphql-java reads a DataFetcherResult only as the value itself, never inside an Optional
108- Unwrapped .Present -> if (next != null || unwrapped.getOrNull(i + 1 ) == Unwrapped .Data ) ValueOf (next) else null
109- Unwrapped .Elements -> next?.let (::EachElement )
110- }
102+ private fun steps (unwrapped : List <Unwrapped >, awaits : Awaitable , peels : Awaitable ): Step ? {
103+ val outermost = unwrapped.firstOrNull() ? : return null
104+ val inner = unwrapped.subList(1 , unwrapped.size)
105+ val next = steps(inner, awaits, peels)
106+ return when (outermost) {
107+ is Unwrapped .Wrapper -> if (outermost.isFuture) Await (outermost.wrapper, awaits, next) else Peel (outermost.wrapper, peels, next)
108+ Unwrapped .Data -> next?.let (::DataOf )
109+ // graphql-java reads a DataFetcherResult and then an Optional in its data, so an Optional around one is ours to unwrap
110+ Unwrapped .Present -> if (next != null || inner.firstOrNull() == Unwrapped .Data ) ValueOf (next) else null
111+ Unwrapped .Elements -> next?.let (::EachElement )
111112 }
113+ }
112114
113115private fun Any?.thenUnlessNextAwaits (next : Step ? , environmentSupplier : Supplier <DataFetchingEnvironment >): Any? =
114116 if (next is Await ) next.unwrap(this , environmentSupplier) else then(next, environmentSupplier)
0 commit comments