NRedisGraph
NRedisGraph copied to clipboard
Support map as parameter
I am running the following code:
var assignments = new (long ScopeId, long RoleId, long UserId)[]
{
(123, 234, 345),
(321, 432, 543),
}
var assignmentMaps = assignments.Select(a => new { scopeId = a.ScopeId, roleId = a.RoleId, userId = a.UserId }).ToArray();
await graph.QueryAsync(AuthGraphKey,
query: "UNWIND $assignments AS assignment " +
"MATCH (s:Scope { id: assignment.scopeId }), (r:Role { id: assignment.roleId }) " +
"CREATE (s)-[:ASSIGNED_TO { user_id: assignment.userId }]->(r)",
parameters: new Dictionary<string, object> {
{ "assignments", assignmentMaps },
});
However, I get an exception from RedisGraph:
Exception: StackExchange.Redis.RedisServerException: errMsg: Invalid input 'a': expected ';', ':', a statement option, a query hint, a clause or a schema command line: 1, column: 1, offset: 0 errCtx: assignments=[{ scopeId = 1044, roleId = 1, userId = 12291 }, { scopeId = 1045... errCtxOffset: 0 at NRedisGraph.RedisGraph.QueryAsync(String graphId, String query) at GlobalEditAPI.Authorization.Core.Infrastructure.Data.IO.RedisGraphAdapter.QueryAsync(String graphId, String query, IDictionary
2 parameters)`
From its formatting, I assume this is because when you provide a "map" type as a parameter, the utility calls .ToString()
instead of serializing as json. We should do that serialization, so we can support map types.
So I'm tinkering around with this, and I THINK the issue is a limitation either with the Cypher query language or the implementation of the Cypher query language that ships with RedisGraph.
Let's try this:
- [ ] Create a unit test in the
RedisGraphUtilitiesTests
class that asserts that the formatted query result matches a known good formatted Cypher query. - [ ] Create an integration test in the
RedisGraphAPITest
class demonstrating that the formatted Cypher query yields the expected result.
Alright, just pushed up changes. These are good catches, thanks for poiting it out. GraphQL doesn't use standard JSON formatting, so had to modify the configuration of the serializer. The "good" query (with the UNWIND) that I use in the integration test is one I tested against RedisInsights, and it works correctly.