public PolicyExampleMutations(Persistence persistence) { Field <CommandExecutionResultGraphType>() .Name("createNewLogicGraph") .Argument <CreateLogicGraphCommandGraphType>("command") .Resolve(ctx => { var command = ctx.GetArgument <CreateLogicGraphCommand>("command"); var logicGraphDomainObject = new LogicGraphEntity() { Id = Guid.NewGuid().ToString(), Name = command.Name, Graph = new LogicGraph() { ExecutionFlow = new OrderedExecutionFlow(new JintNodeExecutor()) } }; persistence.Graphs.Add(logicGraphDomainObject); return(new CreateLogicGraphResult() { Success = true, LogicGraphId = logicGraphDomainObject.Id }); }); Field <RunLogicGraphResultGraphType>() .Name("runLogicGraph") .Argument <RunLogicGraphCommandGraphType>("command") .ResolveAsync(async ctx => { var command = ctx.GetArgument <RunLogicGraphCommand>("command"); try { var graph = persistence.Graphs.First(g => g.Id == command.LogicGraphId); var results = await graph.Graph.Run().ToListAsync(); return(new RunLogicGraphResult() { Success = true, RunReport = new RunReport() { Id = command.Id, Trace = results.Select(ToNodeExecutionResult).ToList() } }); } catch (Exception ex) { return(new RunLogicGraphResult() { Errors = new List <string>() { "Cannot run graph " + command.LogicGraphId, ex.ToString() }, Success = false }); } }); Field <CommandExecutionResultGraphType>() .Name("createNewLogicNode") .Argument <CreateLogicNodeCommandGraphType>("command") .Resolve(ctx => { try { var command = ctx.GetArgument <CreateLogicNodeCommand>("command"); var graph = persistence.Graphs.First(g => g.Id == command.LogicGraphId); var logicGraphDomainObject = new LogicNode() { Id = Guid.NewGuid().ToString(), Name = command.Name, }; if (command.Script?.Body != null) { logicGraphDomainObject.Script = new Script(command.Script?.Body); } if (graph.Graph.Root == null) { graph.Graph.Root = logicGraphDomainObject; return(new CreateLogicNodeResult() { Success = true, LogicNodeId = logicGraphDomainObject.Id }); } var parentNode = graph.Graph.Root.GetTree() .FirstOrDefault(n => n.Id == command.ParentNodeId); if (parentNode == null) { return(new CreateLogicNodeResult() { Errors = new List <string>() { "Cannot find parent node with id " + command.ParentNodeId }, Success = false }); } logicGraphDomainObject.Parent = parentNode; parentNode.Children.Add(logicGraphDomainObject); return(new CreateLogicNodeResult() { Success = true, LogicNodeId = logicGraphDomainObject.Id }); } catch (Exception ex) { return(new CreateLogicNodeResult() { Success = false, Errors = new List <string>() { ex.ToString() } }); } }); }
public NodeFlowService(LogicNode node) { _node = node; }