public static QueryPlan Build(IPreparedOperation operation) { if (operation is null) { throw new ArgumentNullException(nameof(operation)); } var context = new QueryPlanContext(operation); OperationNode operationNode = Prepare(context); QueryPlan[] deferredPlans = operationNode.Deferred.Count > 0 ? new QueryPlan[operationNode.Deferred.Count] : Array.Empty <QueryPlan>(); Dictionary <int, QueryPlan>?streamPlans = context.Streams.Count > 0 ? new Dictionary <int, QueryPlan>() : null; if (operationNode.Deferred.Count > 0) { for (var i = 0; i < operationNode.Deferred.Count; i++) { deferredPlans[i] = new QueryPlan( operationNode.Deferred[i].CreateStep(), deferredPlans, streamPlans); } } if (context.Streams.Count > 0) { foreach (StreamPlanNode streamPlanNode in context.Streams.Values) { var streamPlan = new QueryPlan( streamPlanNode.Root.CreateStep(), deferredPlans, streamPlans); streamPlans !.Add(streamPlanNode.Id, streamPlan); } } return(new QueryPlan(operationNode.CreateStep(), deferredPlans, streamPlans)); }
public static OperationNode Build(QueryPlanContext context) { var root = new SequenceNode { CancelOnError = true }; context.Root = root; context.NodePath.Push(root); foreach (ISelection mutation in context.Operation.GetRootSelectionSet().Selections) { context.SelectionPath.Push(mutation); var mutationStep = new ResolverNode( mutation, context.SelectionPath.PeekOrDefault(), GetStrategyFromSelection(mutation)); root.AddNode(mutationStep); QueryStrategy.VisitChildren(mutation, context); } context.NodePath.Pop(); QueryPlanNode optimized = QueryStrategy.Optimize(context.Root); var operationNode = new OperationNode(optimized); if (context.Deferred.Count > 0) { foreach (var deferred in QueryStrategy.BuildDeferred(context)) { operationNode.Deferred.Add(deferred); } } if (context.Streams.Count > 0) { operationNode.Streams.AddRange(context.Streams.Values); } return(operationNode); }
public static OperationNode Build(QueryPlanContext context) { QueryPlanNode root = Build(context, context.Operation.GetRootSelectionSet()); var operationNode = new OperationNode(root); if (context.Deferred.Count > 0) { foreach (var deferred in BuildDeferred(context)) { operationNode.Deferred.Add(deferred); } } if (context.Streams.Count > 0) { operationNode.Streams.AddRange(context.Streams.Values); } return(operationNode); }