neo4jclient Why does executing this query work from the browser but not via the app

60 Views Asked by At

For some reason executing the query via the code gives error but if I type it directly in the terminal(browser) it goes through. My code:

var accountGuids = match.PlayerIDsScores.Keys.ToArray();
var gameScores = match.PlayerIDsScores.Values.ToArray();
    var query = _neo.Cypher
        .Match("(q:Quiz)")
        .Where((Quiz q) => q.ID == match.QuizID)
        .Merge("(m:Match $prop)-[u:USED]->(q)")
        .WithParams( new { prop = matchPoco})
        .With("m, $propac AS accounts, $propscore AS scores")
        .WithParams( new { propac = accountGuids, propscore = gameScores})
        .Unwind("range(0,size(accounts)-1)", "index")
        .OptionalMatch("(a:Account)")
        .Where("a.ID = accounts[index]")
        .Merge("(a)-[p:PARTICIPATED_IN]->(m)")
        .Set("p.GameScore = scores[index]");
    Console.WriteLine(query.Query.DebugQueryText);
    await query.ExecuteWithoutResultsAsync();

The string I got with Console.WriteLine:

MATCH (q:Quiz)
WHERE (q.ID = "fafbcc2f-fd67-42c9-bd65-7609142e041e")
MERGE (m:Match {
  ID: "3fa95f64-5717-4562-b3fc-2c963f66afa6",
  Created: "\"2023-01-07T09:37:10.197Z\"",
  InviteCode: "string",
  GameState: "Waiting",
  HostID: "c098d8d4-a913-49c8-9a5e-18c5d60967a9",
  WinnerID: "c098d8d4-a913-49c8-9a5e-18c5d60967a9",
  Guests: "{\"additionalProp1\":15,\"additionalProp2\":0,\"additionalProp3\":0}"
})-[u:USED]->(q)
WITH m, [
  "c098d8d4-a913-49c8-9a5e-18c5d60967a9",
  "d4771807-4bea-406f-a1d9-8b690bb49c1b",
  "debe6b96-f151-4080-a4b4-d27f56bac0f3"
] AS accounts, [
  100,
  75,
  50
] AS scores
UNWIND range(0,size(accounts)-1) AS index
OPTIONAL MATCH (a:Account)
WHERE a.ID = accounts[index]
MERGE (a)-[p:PARTICIPATED_IN]->(m)
SET p.GameScore = scores[index]

And the error message is:

at Neo4jClient.GraphClient.Neo4jClient.IRawGraphClient.ExecuteCypherAsync(CypherQuery query)
   at MatchService.SaveMatchQueryAsync(Match match)
   at MatchService.SaveMatchAsync(Match match)
   at MatchController.SaveMatch(Match match)
   at lambda_method68(Closure, Object)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker 
invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) 
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable 
scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable 
scope)

If I copy/paste the string that I got from Console.WriteLine(query.Query.DebugQueryText) into the browser terminal it executes without any problems, but when I try to do it with .ExecuteWithoutResultsAsync() it gives me an error

1

There are 1 best solutions below

0
Lajron On

Aight found the fix, turns out for some reason I can't do this:

.Merge("(m:Match $prop)-[u:USED]->(q)")
    .WithParams( new { prop = matchPoco})

I had to do it manually...

.Merge("(m:Match { ID: $mID, Created: $mCreated, InviteCode: $mInviteCode, GameState: $mGameState, HostID: $mHostID , WinnerID: $mWinnerID, Guests: $mGuests})-[u:USED]->(q)")
        .WithParams( new { 
            mID = matchPoco.ID,
            mCreated = matchPoco.Created,
            mInviteCode = matchPoco.InviteCode,
            mGameState = matchPoco.GameState,
            mHostID = matchPoco.HostID,
            mWinnerID = matchPoco.WinnerID,
            mGuests = matchPoco.Guests 
            })