Skip to content

Commit a592551

Browse files
author
Oleksandr Dzhychko
authored
Merge pull request #1296 from modelix/bugfix/MODELIX-997
fix(modelql): set `INodeResolutionScope` when running query on `INode`
2 parents dcae883 + f8861f5 commit a592551

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

modelql-untyped/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ kotlin {
1717
}
1818
val commonTest by getting {
1919
dependencies {
20+
implementation(project(":model-datastructure"))
2021
implementation(kotlin("test"))
22+
implementation(libs.kotlin.coroutines.test)
2123
}
2224
}
2325
val jvmMain by getting {

modelql-untyped/src/commonMain/kotlin/org/modelix/modelql/untyped/UntypedModelQL.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ fun INode.createQueryExecutor(): IQueryExecutor<INode> {
6464
}
6565

6666
suspend fun <R> INode.query(body: (IMonoStep<INode>) -> IMonoStep<R>): R {
67-
return buildQuery(body).execute().value
67+
return this.getArea().runWithAdditionalScopeInCoroutine {
68+
buildQuery(body).execute().value
69+
}
6870
}
6971

7072
suspend fun <R> INode.queryFlux(body: (IMonoStep<INode>) -> IFluxStep<R>): List<R> {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package org.modelix.modelql.untyped
15+
16+
import kotlinx.coroutines.test.runTest
17+
import org.modelix.model.api.TreePointer
18+
import org.modelix.model.api.getRootNode
19+
import org.modelix.model.client.IdGenerator
20+
import org.modelix.model.lazy.CLTree
21+
import org.modelix.model.lazy.NonCachingObjectStore
22+
import org.modelix.model.persistent.MapBaseStore
23+
import kotlin.test.Test
24+
import kotlin.test.assertEquals
25+
26+
class UntypedModelQLTest {
27+
private val tree = CLTree(NonCachingObjectStore(MapBaseStore()))
28+
private val branch = TreePointer(tree, IdGenerator.getInstance(1))
29+
private val rootNode = branch.getRootNode()
30+
31+
@Test
32+
fun nodeCanBeResolvedInQuery() = runTest {
33+
val resolvedNode = rootNode.query { root ->
34+
root.nodeReference().resolve()
35+
}
36+
assertEquals(rootNode.reference, resolvedNode.reference)
37+
}
38+
}

0 commit comments

Comments
 (0)