Exemple #1
0
        private void ResolveInlineFragment(
            CompilerContext context,
            InlineFragmentNode inlineFragment,
            SelectionIncludeCondition?includeCondition)
        {
            if (inlineFragment.SelectionSet.Selections.Count == 0)
            {
                throw OperationCompiler_FragmentNoSelections(inlineFragment);
            }

            if (_fragments.GetFragment(context.Type, inlineFragment) is { } fragmentInfo&&
                DoesTypeApply(fragmentInfo.TypeCondition, context.Type))
            {
                var reference = new SpreadReference(context.SelectionPath, inlineFragment);

                if (!context.Spreads.TryGetValue(reference, out var selectionSet))
                {
                    selectionSet = inlineFragment.SelectionSet.WithSelections(
                        inlineFragment.SelectionSet.Selections);
                    context.Spreads.Add(reference, selectionSet);
                }

                if (inlineFragment.IsDeferrable() &&
                    AllowFragmentDeferral(context, inlineFragment))
                {
                    CompilerContext deferContext = context.Branch(selectionSet);
                    CompileSelectionSet(deferContext);

                    context.RegisterFragment(new Fragment(
                                                 _nextFragmentId++,
                                                 context.Type,
                                                 inlineFragment,
                                                 deferContext.GetSelectionSet(),
                                                 context.IsInternalSelection,
                                                 includeCondition));
                }
                else
                {
                    CollectFields(
                        context,
                        selectionSet,
                        includeCondition);
                }
            }
        }
Exemple #2
0
    private void ResolveFragmentSpread(
        CompilerContext context,
        FragmentSpreadNode fragmentSpread,
        SelectionIncludeCondition?includeCondition)
    {
        if (_fragments.GetFragment(fragmentSpread.Name.Value) is { } fragmentInfo&&
            DoesTypeApply(fragmentInfo.TypeCondition, context.Type))
        {
            FragmentDefinitionNode fragmentDefinition = fragmentInfo.FragmentDefinition !;

            if (fragmentDefinition.SelectionSet.Selections.Count == 0)
            {
                throw OperationCompiler_FragmentNoSelections(fragmentDefinition);
            }

            var reference = new SpreadReference(context.SelectionPath, fragmentSpread);

            if (!context.Spreads.TryGetValue(reference, out SelectionSetNode? selectionSet))
            {
                selectionSet = fragmentDefinition.SelectionSet.WithSelections(
                    fragmentDefinition.SelectionSet.Selections);
                context.Spreads.Add(reference, selectionSet);
            }

            if (fragmentSpread.IsDeferrable() &&
                AllowFragmentDeferral(context, fragmentSpread, fragmentDefinition))
            {
                CompilerContext deferContext = context.Branch(selectionSet);
                CompileSelectionSet(deferContext);

                context.RegisterFragment(new Fragment(
                                             _nextFragmentId++,
                                             context.Type,
                                             fragmentSpread,
                                             fragmentDefinition,
                                             deferContext.GetSelectionSet(),
                                             context.IsInternalSelection,
                                             includeCondition));
            }
            else
            {
                CollectFields(context, selectionSet, includeCondition);
            }
        }
    }