private string GetDataList(dynamic set) { dynamic tableInst = null; foreach (var table in set.Fields) { tableInst = Activator.CreateInstance(table.Type); if (tableInst is ListGraphType) { continue; } else { break; } } return($@"export const GET_{tableInst.Name.ToUpper()}_List = searchFields => {{ return gql` query {nameof(BasicRepository<object>.QueryList)}(${SystemCP.Condition}: String!, ${SystemCP.JWT}: String!){{ {nameof(BasicRepository<object>.QueryList)}({SystemCP.Condition}: ${SystemCP.Condition}, {SystemCP.JWT}: ${SystemCP.JWT}){{ ${{searchFields || ""...{LibData.ToCamelCase(tableInst.Name)}List""}} }} }} ${{searchFields ? """" : {LibData.ToCamelCase(set.Name)}Fragment.{LibData.ToCamelCase(tableInst.Name)}List}} `; }}; "); }
private string Template(dynamic set) { string tableTemplate = string.Empty; foreach (var table in set.Fields) { dynamic tableInst = Activator.CreateInstance(table.Type); if (tableInst is ListGraphType) { tableInst = Activator.CreateInstance(tableInst.Type); } else { tableTemplate += GetTableTemplate(tableInst, $"{tableInst.Name}List"); } tableTemplate += GetTableTemplate(tableInst, tableInst.Name); } return($@"import {{ gql }} from ""apollo-boost""; const {LibData.ToCamelCase(set.Name)}Fragment = {{ {tableTemplate} }}; export default {LibData.ToCamelCase(set.Name)}Fragment; "); }
private string GetTableTemplate(dynamic tableInst, string fragName) { string fields = GetFieldsTemplate(tableInst); return($@" {LibData.ToCamelCase(fragName)}: gql` fragment {LibData.ToCamelCase(fragName)} on {tableInst.Name} {{ {fields} }}`, "); }
private string GetFieldsTemplate(dynamic tableInst) { StringBuilder str = new StringBuilder(); foreach (var field in tableInst.Fields) { str.AppendLine($" {LibData.ToCamelCase(field.Name)}"); } return(str.ToString()); }
private void CreateFragment() { foreach (Type type in GraphTypes) { string[] strs = type.Namespace.Split('.'); string subPath = string.Empty; for (int i = 2; i < strs.Length; i++) { subPath = LibData.Merge(@"/", false, subPath, strs[i].ToCamelCase()); } string fullPath = LibData.Merge(@"/", false, Path, subPath); Directory.CreateDirectory(fullPath); dynamic set = Activator.CreateInstance(type); using StreamWriter file = new StreamWriter($@"{fullPath}/{LibData.ToCamelCase(set.Name)}.fragment.js", true); file.Write(Template(set)); } }
private string Template(string subPath, dynamic set) { string frontDir = string.Empty; int subLv = subPath.Split('/').Length; for (int i = 0; i < subLv; i++) { frontDir = LibData.Merge("/", false, frontDir, ".."); } string fullPath = LibData.Merge("/", false, frontDir, "../fragments", subPath, $"{ LibData.ToCamelCase(set.Name)}.fragment"); return($@"import {{ gql }} from ""apollo-boost""; import {LibData.ToCamelCase(set.Name)}Fragment from ""{fullPath}""; {GetDataList(set)} {GetDataInfo(set)} "); }
private string Template(string subPath, dynamic set) { List <dynamic> tableInstList = new List <dynamic>(); foreach (var table in set.Fields) { dynamic tableInst = Activator.CreateInstance(table.Type); if (tableInst is ListGraphType) { tableInst = Activator.CreateInstance(tableInst.Type); } tableInstList.Add(tableInst); } string frontDir = string.Empty; int subLv = subPath.Split('/').Length; for (int i = 0; i < subLv; i++) { frontDir = LibData.Merge("/", false, frontDir, ".."); } string fullPath = LibData.Merge("/", false, frontDir, "../fragments", subPath, $"{ LibData.ToCamelCase(set.Name)}.fragment"); return($@"import {{ gql }} from ""apollo-boost""; import {LibData.ToCamelCase(set.Name)}Fragment from ""{fullPath}""; {GetReturnedFields(set.Name, tableInstList)} {GetCreate(set.Name, tableInstList.Count)} {GetUpdate(set.Name, tableInstList.Count)} {GetDelete(set.Name, tableInstList.Count)} {GetApprove(set.Name, tableInstList.Count)} {GetInvalid(set.Name, tableInstList.Count)} {GetEndcase(set.Name, tableInstList.Count)} "); }
private string GetCondition(string setName, dynamic tableInst, int count) { return($@"${{search{count} ? """" : {LibData.ToCamelCase(setName)}Fragment.{LibData.ToCamelCase(tableInst.Name)}}}"); }
private string GetDetailSearch(dynamic tableInst, int count) { return($@" {LibData.ToCamelCase(tableInst.Name)} {{ ${{search{count} || ""...{LibData.ToCamelCase(tableInst.Name)}""}} }}"); }