示例#1
0
        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);
            }
        }
示例#2
0
        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));
        }