コード例 #1
0
        private static void Visit(ISelection selection, QueryPlanContext context)
        {
            if (selection.IsStreamable && selection.SelectionSet is not null)
            {
                QueryPlanContext streamContext = context.Branch();

                VisitChildren(selection, streamContext);

                if (streamContext.Root is not null &&
                    !context.Streams.ContainsKey(selection.Id))
                {
                    context.Streams.Add(selection.Id, new(selection.Id, streamContext.Root));
                }

                if (streamContext.Streams.Count > 0)
                {
                    foreach (StreamPlanNode streamPlan in streamContext.Streams.Values)
                    {
                        if (!context.Streams.ContainsKey(selection.Id))
                        {
                            context.Streams.Add(selection.Id, streamPlan);
                        }
                    }
                }
            }

            if (context.NodePath.Count == 0)
            {
                context.Root = new ResolverNode(selection);
                context.NodePath.Push(context.Root);
            }
            else
            {
                QueryPlanNode parent = context.NodePath.Peek();

                if (selection.Strategy == SelectionExecutionStrategy.Serial)
                {
                    if (parent is ResolverNode {
                        Strategy : ExecutionStrategy.Serial
                    } p)
                    {
                        p.Selections.Add(selection);
                    }
                    else if (context.SelectionPath.Count > 0 &&
                             context.NodePath.TryPeek(2, out QueryPlanNode? grandParent) &&
                             grandParent is ResolverNode {
                        Strategy: ExecutionStrategy.Serial
                    } gp&&
                             gp.Selections.Contains(context.SelectionPath.PeekOrDefault() !))
                    {
                        gp.Selections.Add(selection);
                    }