static void Run(GenContext context, Operation operation)
        {
            var ns = new GenNamespace
            {
                Operation = operation,
                Name      = operation.Name,
                Context   = context
            };

            var rootType = context.Schema.FindType(ns.Operation.OperationType.ToString());
            var rootSet  = ns.CreateSelectionSet(rootType, context.Document);

            Run(context, operation.SelectionSet, rootSet);
            ns.Root = rootSet;

            foreach (var variable in operation.Variables)
            {
                var graphType = context.Schema.FindType(variable.Type.Name());
                var reference = ns.CreateReference(graphType, variable.NameNode);
                rootSet.AddVariable(variable.Name, reference);
                Run(reference.GetSelectionSet());
            }

            context.Namespaces.Add(ns);
        }
        static string NamespaceDeclarionName(GenContext context, GenNamespace ns)
        {
            var name = context.Config.Namespace + ".Model";

            if (!string.IsNullOrWhiteSpace(ns.Name))
            {
                name += "." + ns.Name;
            }
            return(name);
        }
        static void RenderNamespace(StringBuilder text, GenContext context, GenNamespace ns)
        {
            text.AppendLine();
            text.AppendLine("namespace " + NamespaceDeclarionName(context, ns));
            text.AppendLine("{");

            var useInterface = ns == context.Fragments;

            foreach (var genType in ns.SelectionSets)
            {
                if (useInterface)
                {
                    RenderInterface(text, context, genType);
                }
                else
                {
                    RenderClass(text, context, genType);
                }
            }

            text.AppendLine("}");
        }
 public GenContext()
 {
     Fragments = new GenNamespace {
         Name = "Fragments", Context = this
     };
 }