Skip to content

Commit

Permalink
Implemented graphql endpoint latestChangeAll for trait entities
Browse files Browse the repository at this point in the history
  • Loading branch information
maximiliancsuk committed Oct 11, 2023
1 parent 1ca5643 commit 2c37f1d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
15 changes: 15 additions & 0 deletions backend/Omnikeeper/GraphQL/TraitEntities/TraitEntityTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ public TraitEntityRootType(ITrait at, IEffectiveTraitModel effectiveTraitModel,
var ets = await traitEntityModel.GetByCIID(AllCIIDsSelection.Instance, layerset, trans, timeThreshold);
return ets.Select(kv => kv.Value);
});
Field<ChangesetType>("latestChangeAll")
.Description("Note: the implementation that calculates the latest relevant changeset is done rather defensively. That means there are circumstances " +
"where this field returns a new/later changeset even though there are no (visible) changes to the trait entities themselves. However, it will never NOT report " +
"a new changeset when there have been changes to the trait entities. This behavior makes it reasonably suitable for implementing a client-side cache that only " +
"fetches new data when anything has changed")
.ResolveAsync(async context =>
{
var userContext = (context.UserContext as OmnikeeperUserContext)!;
var layerset = userContext.GetLayerSet(context.Path);
var timeThreshold = userContext.GetTimeThreshold(context.Path);
var trans = userContext.Transaction;
// TODO: use dataloader
return await traitEntityModel.GetLatestRelevantChangesetOverallHeuristic(AllCIIDsSelection.Instance, layerset, trans, timeThreshold);
});

Field("filtered", new ListGraphType(wrapperElementGraphType))
.Arguments(
Expand Down
49 changes: 41 additions & 8 deletions backend/Tests/Integration/GraphQL/BasicTraitEntityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public async Task TestBasics()
assignments { relatedCIID }
}
}
latestChangeAll {
userID
layerID
}
}
}
}
Expand All @@ -118,7 +122,8 @@ public async Task TestBasics()
{
""traitEntities"": {
""test_trait_a"": {
""all"": []
""all"": [],
""latestChangeAll"": null
}
}
}
Expand Down Expand Up @@ -166,7 +171,11 @@ public async Task TestBasics()
}]
}
}
]
],
""latestChangeAll"": {
""userID"": " + userInDatabase.ID + @",
""layerID"": ""layer_1""
}
}
}
}
Expand Down Expand Up @@ -213,7 +222,11 @@ public async Task TestBasics()
}]
}
}
]
],
""latestChangeAll"": {
""userID"": " + userInDatabase.ID + @",
""layerID"": ""layer_1""
}
}
}
}
Expand Down Expand Up @@ -284,7 +297,11 @@ public async Task TestBasics()
}}]
}}
}}
]
],
""latestChangeAll"": {{
""userID"": " + userInDatabase.ID + $@",
""layerID"": ""layer_1""
}}
}}
}}
}}
Expand Down Expand Up @@ -325,7 +342,11 @@ public async Task TestBasics()
}}]
}}
}}
]
],
""latestChangeAll"": {{
""userID"": " + userInDatabase.ID + $@",
""layerID"": ""layer_1""
}}
}}
}}
}}
Expand Down Expand Up @@ -380,7 +401,11 @@ public async Task TestBasics()
}}]
}}
}}
]
],
""latestChangeAll"": {{
""userID"": " + userInDatabase.ID + $@",
""layerID"": ""layer_1""
}}
}}
}}
}}
Expand Down Expand Up @@ -432,7 +457,11 @@ public async Task TestBasics()
}}]
}}
}}
]
],
""latestChangeAll"": {{
""userID"": " + userInDatabase.ID + $@",
""layerID"": ""layer_1""
}}
}}
}}
}}
Expand Down Expand Up @@ -462,7 +491,11 @@ public async Task TestBasics()
{{
""traitEntities"": {{
""test_trait_a"": {{
""all"": []
""all"": [],
""latestChangeAll"": {{
""userID"": " + userInDatabase.ID + $@",
""layerID"": ""layer_1""
}}
}}
}}
}}
Expand Down

0 comments on commit 2c37f1d

Please sign in to comment.