コード例 #1
0
        private ICollection <ISelectionNode> ResolveSelections(IEnumerable <ISelection> selections, Dictionary <string, IFragment> fragements)
        {
            var list = new List <ISelectionNode>();

            foreach (var selection in selections)
            {
                if (selection is InlineFragment inlineFragment)
                {
                    var graphType = _graphTypeProvider.GetGraphType(inlineFragment.Type.Name);
                    var fragment  = new Fragment(graphType);
                    foreach (var item in ResolveSelections(inlineFragment.SelectionSet.Selections, fragements))
                    {
                        fragment.AddSubSelection(item);
                    }
                    list.Add(fragment);
                }
                if (!(selection is Field field))
                {
                    continue;
                }
                var fieldSelection = new FieldSelection(field.Name)
                {
                    Alias = field.Alias
                };

                if (field.SelectionSet.Selections.FirstOrDefault() is FragmentSpread fragmentSpread)
                {
                    var fragmentType = fragements[fragmentSpread.Name];
                }

                foreach (var directiveDefinition in field.Directives)
                {
                    var directive = new Directive(directiveDefinition.Name);
                    foreach (var argument in directiveDefinition.Arguments)
                    {
                        directive.AddArgument(new NamedValueToken(argument.Name, argument.Value.Value, argument.Value is VariableReference));
                    }
                    fieldSelection.Directives.Add(directive);
                }

                foreach (var argument in field.Arguments)
                {
                    fieldSelection.AddArgument(new NamedValueToken(argument.Name, argument.Value.Value, argument.Value is VariableReference));
                }

                var subSelections = ResolveSelections(field.SelectionSet.Selections, fragements);
                foreach (var subSelection in subSelections)
                {
                    fieldSelection.AddSubSelection(subSelection);
                }
                list.Add(fieldSelection);
            }
            return(list);
        }