Пример #1
0
        static void Run(GenContext context, SelectionSet set, GenSelectionSet selectionSet)
        {
            foreach (var selection in set.Selections)
            {
                switch (selection)
                {
                case Field field:
                {
                    var fieldType = ((ObjectGraphType)selectionSet.GraphType).GetField(field.Name);

                    var propertyType = selectionSet.Namespace.CreateReference(fieldType.ResolvedType, field);
                    selectionSet.AddField(field.Alias ?? field.Name, propertyType);

                    Run(context, field.SelectionSet, propertyType.GetSelectionSet());

                    break;
                }

                case FragmentSpread fragment:
                {
                    var fragmentType = context.Fragments.SelectionSets.Find(t => t.Name == fragment.Name);
                    selectionSet.AddFragment(fragmentType);
                    break;
                }

                case InlineFragment inline:
                {
                    throw new NotImplementedException();
                }

                default:
                    throw new InvalidOperationException("Uh whats that?");
                }
            }
        }
Пример #2
0
        static void Run(GenSelectionSet set)
        {
            switch (set.GraphType)
            {
            case IComplexGraphType complexType:
            {
                foreach (var fieldType in complexType.Fields)
                {
                    var fieldReference = set.Namespace.CreateReference(fieldType.ResolvedType, null);
                    set.AddField(fieldType.Name, fieldReference);
                    Run(fieldReference.GetSelectionSet());
                }
                break;
            }

            default:
                return;
            }
        }