public static string Generate(TypeModel type, string rootNamespace, string queryType) { switch (type.Kind) { case TypeKind.Object: if (type.Name == queryType) { return(EntityGenerator.GenerateRoot(type, rootNamespace)); } else { return(EntityGenerator.Generate(type, rootNamespace)); } case TypeKind.Interface: return(InterfaceGenerator.Generate(type, rootNamespace)); case TypeKind.Enum: return(EnumGenerator.Generate(type, rootNamespace)); case TypeKind.InputObject: return(InputObjectGenerator.Generate(type, rootNamespace)); case TypeKind.Union: return(UnionGenerator.Generate(type, rootNamespace)); default: return(null); } }
private static string GenerateStub(TypeModel type, string entityNamespace, string queryType) { var stubType = type.Clone(); stubType.Name = "Stub" + TypeUtilities.GetInterfaceName(type); stubType.Kind = TypeKind.Object; stubType.Interfaces = new[] { type }; return(EntityGenerator.Generate(stubType, entityNamespace + ".Internal", queryType, entityNamespace: entityNamespace, modifiers: "internal ", generateDocComments: false)); }
private static string GenerateStub(TypeModel type, string rootNamespace) { var stubType = type.Clone(); stubType.Name = "Stub" + TypeUtilities.GetInterfaceName(type); stubType.Kind = TypeKind.Object; stubType.Interfaces = new[] { type }; return(EntityGenerator.Generate(stubType, rootNamespace + ".Internal", "internal ", false, rootNamespace)); }
public static GeneratedFile Generate(TypeModel type, string rootNamespace, string queryType, string entityNamespace = null) { entityNamespace = entityNamespace ?? rootNamespace; var inModelFolder = true; string result = null; switch (type.Kind) { case TypeKind.Object: if (type.Name == queryType || type.Name == "Mutation") { var interfaceName = "IQuery"; if (type.Name != queryType) { interfaceName = "I" + type.Name; } result = EntityGenerator.GenerateRoot(type, rootNamespace, entityNamespace, interfaceName, queryType); inModelFolder = false; } else { result = EntityGenerator.Generate(type, entityNamespace, queryType, entityNamespace: entityNamespace); } break; case TypeKind.Interface: result = InterfaceGenerator.Generate(type, entityNamespace, queryType); break; case TypeKind.Enum: result = EnumGenerator.Generate(type, entityNamespace); break; case TypeKind.InputObject: result = InputObjectGenerator.Generate(type, entityNamespace); break; case TypeKind.Union: result = UnionGenerator.Generate(type, entityNamespace); break; } var fileName = type.Name + ".cs"; if (inModelFolder) { fileName = Path.Combine("Model", fileName); } return(new GeneratedFile(fileName, result)); }