Пример #1
0
 public PossibleSelections CollectFields(
     INamedOutputType type,
     SelectionSetNode selectionSet,
     Path path) =>
 _collector.CollectFields(type, selectionSet, path);
Пример #2
0
 protected virtual ISyntaxVisitorAction Enter(
     SelectionSetNode node,
     TContext context) =>
 DefaultAction;
Пример #3
0
 public SelectionVariants(SelectionSetNode selectionSet)
 {
     SelectionSet = selectionSet;
 }
Пример #4
0
 public SelectionSetInfo(INamedType type, SelectionSetNode selectionSet)
 {
     Type         = type;
     SelectionSet = selectionSet;
 }
Пример #5
0
 public Fragment(string name, INamedType typeCondition, SelectionSetNode selectionSet)
 {
     Name          = name;
     TypeCondition = typeCondition ?? throw new ArgumentNullException(nameof(typeCondition));
     SelectionSet  = selectionSet ?? throw new ArgumentNullException(nameof(selectionSet));
 }
Пример #6
0
 public IEnumerable <IObjectType> GetPossibleTypes(SelectionSetNode selectionSet)
 {
     return(_selectionSets.TryGetValue(selectionSet, out SelectionVariants? variants)
         ? variants.GetPossibleTypes()
         : Enumerable.Empty <IObjectType>());
 }
Пример #7
0
 public ISelectionSet CollectFields(
     SelectionSetNode selectionSet,
     ObjectType objectType) =>
 Operation.GetSelectionSet(selectionSet, objectType);
Пример #8
0
 protected virtual ISyntaxVisitorAction Leave(
     SelectionSetNode node,
     ISyntaxVisitorContext context) =>
 DefaultAction;
Пример #9
0
        private void Visit(
            SelectionSetNode selectionSet,
            ObjectType typeContext,
            Stack <IObjectField> fieldContext,
            PSS current,
            Action <PSS> register,
            IDictionary <ISelectionNode, SelectionIncludeCondition> includeConditionLookup,
            List <ISelectionSetOptimizer> optimizers,
            bool internalSelection = false)
        {
            // we first collect the fields that we find in the selection set ...
            IDictionary <string, PreparedSelection> fields =
                CollectFields(typeContext, selectionSet, includeConditionLookup, internalSelection);

            // ... after that is done we will check if there are query optimizer that want
            // to provide additional fields.
            OptimizeSelectionSet(fieldContext, typeContext, selectionSet, fields, optimizers);

            var selections    = new List <PreparedSelection>();
            var isConditional = false;

            foreach (PreparedSelection selection in fields.Values)
            {
                // we now make the selection read-only and add it to the final selection-set.
                selection.MakeReadOnly();
                selections.Add(selection);

                // if one selection of a selection-set is conditional,
                // then the whole set is conditional.
                if (!isConditional && (selection.IsConditional || selection.IsInternal))
                {
                    isConditional = true;
                }

                // if the field of the selection returns a composite type we will traverse
                // the child selection-sets as well.
                INamedType fieldType = selection.Field.Type.NamedType();
                if (fieldType.IsCompositeType())
                {
                    if (selection.SelectionSet is null)
                    {
                        // composite fields always have to have a selection-set
                        // otherwise we need to throw.
                        throw QueryCompiler_CompositeTypeSelectionSet(selection.Selection);
                    }

                    var next = new PSS(selection.SelectionSet);
                    register(next);

                    IReadOnlyList <ObjectType> possibleTypes = _schema.GetPossibleTypes(fieldType);
                    for (var i = 0; i < possibleTypes.Count; i++)
                    {
                        // we prepare the field context and check if there are field specific
                        // optimizers that we might want to include.
                        fieldContext.Push(selection.Field);
                        var initialCount = optimizers.Count;
                        var registered   = RegisterOptimizers(optimizers, selection.Field);

                        Visit(
                            selection.SelectionSet,
                            possibleTypes[i],
                            fieldContext,
                            next,
                            register,
                            includeConditionLookup,
                            optimizers,
                            selection.IsInternal);

                        // lets clean up the context again and move on to the next.
                        UnregisterOptimizers(optimizers, initialCount, registered);
                        fieldContext.Pop();
                    }
                }
            }

            current.AddSelections(
                typeContext,
                new PreparedSelectionList(selections, isConditional));
        }
Пример #10
0
 public IPreparedSelectionList CollectFields(
     SelectionSetNode selectionSet,
     ObjectType objectType) =>
 Operation.GetSelections(selectionSet, objectType);
Пример #11
0
 protected virtual void VisitSelectionSet(SelectionSetNode node)
 {
 }