diff --git a/cache/cache.go b/cache/cache.go index 42196d3..371a2e5 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -168,14 +168,17 @@ func enhanceModelsWithFields(enums []*structs.Enum, schema *ast.Schema, cfg *con // log some warnings when fields could not be converted if boilerField.Type == "" { - // TODO: add filter + where here + skipWarningInFilter := + strings.EqualFold(name, "and") || + strings.EqualFold(name, "or") || + strings.EqualFold(name, "search") || + strings.EqualFold(name, "where") || + strings.EqualFold(name, "withDeleted") + switch { case m.IsPayload: case IsPlural(name): - case (m.IsFilter || m.IsWhere) && (strings.EqualFold(name, "and") || - strings.EqualFold(name, "or") || - strings.EqualFold(name, "search") || - strings.EqualFold(name, "where")) || + case ((m.IsFilter || m.IsWhere) && skipWarningInFilter) || isEdges || isSort || isSortDirection || @@ -184,14 +187,14 @@ func enhanceModelsWithFields(enums []*structs.Enum, schema *ast.Schema, cfg *con isNode: // ignore default: - log.Warn().Str("model.field", m.Name+"."+name).Msg("boiler type not available (empty type)") + log.Warn().Str("field", m.Name+"."+name).Msg("no database mapping") } } if boilerField.Name == "" { if m.IsPayload || m.IsFilter || m.IsWhere || m.IsOrdering || m.IsEdge || isPageInfo || isEdges { } else { - log.Warn().Str("model.field", m.Name+"."+name).Msg("boiler type not available") + log.Warn().Str("field", m.Name+"."+name).Msg("no database mapping") continue } } @@ -210,14 +213,15 @@ func enhanceModelsWithFields(enums []*structs.Enum, schema *ast.Schema, cfg *con IsRelation: boilerField.IsRelation, IsRelationAndNotForeignKey: boilerField.IsRelation && !strings.HasSuffix(strings.ToLower(name), "id"), - IsObject: isObject, - IsOr: strings.EqualFold(name, "or"), - IsAnd: strings.EqualFold(name, "and"), - IsPlural: IsPlural(name), - PluralName: Plural(name), - OriginalType: typ, - Description: field.Description, - Enum: enum, + IsObject: isObject, + IsOr: strings.EqualFold(name, "or"), + IsAnd: strings.EqualFold(name, "and"), + IsWithDeleted: strings.EqualFold(name, "withDeleted"), + IsPlural: IsPlural(name), + PluralName: Plural(name), + OriginalType: typ, + Description: field.Description, + Enum: enum, } field.ConvertConfig = getConvertConfig(enums, m, field) m.Fields = append(m.Fields, field) @@ -521,7 +525,7 @@ func getModelsFromSchema(schema *ast.Schema, boilerModels []*structs.BoilerModel // silent continue continue } - log.Warn().Str("model", modelName).Msg("skipped because no database model found") + // log.Warn().Str("model", modelName).Msg("skipped because no database model found") continue } } diff --git a/cache/sqlboiler_parse.go b/cache/sqlboiler_parse.go index fe1a835..23e0540 100644 --- a/cache/sqlboiler_parse.go +++ b/cache/sqlboiler_parse.go @@ -165,10 +165,10 @@ func GetBoilerModels(dir string) ([]*structs.BoilerModel, []*structs.BoilerEnum) } if field.IsRelation && field.Relationship == nil { - log.Debug().Str("model", model.Name).Str("field", field.Name).Msg( - "We could not find the relationship in the generated " + - "boiler structs this could result in unexpected behavior, we marked this field as " + - "non-relational \n") + // log.Debug().Str("model", model.Name).Str("field", field.Name).Msg( + // "We could not find the relationship in the generated " + + // "boiler structs this could result in unexpected behavior, we marked this field as " + + // "non-relational \n") field.IsRelation = false } diff --git a/go.mod b/go.mod index 4087bce..6f8fa29 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,13 @@ module github.com/web-ridge/gqlgen-sqlboiler/v3 go 1.18 require ( - github.com/99designs/gqlgen v0.17.35 - github.com/iancoleman/strcase v0.2.0 - github.com/rs/zerolog v1.29.1 - github.com/vektah/gqlparser/v2 v2.5.8 - github.com/volatiletech/strmangle v0.0.5 - golang.org/x/mod v0.12.0 - golang.org/x/tools v0.11.0 + github.com/99designs/gqlgen v0.17.43 + github.com/iancoleman/strcase v0.3.0 + github.com/rs/zerolog v1.31.0 + github.com/vektah/gqlparser/v2 v2.5.11 + github.com/volatiletech/strmangle v0.0.6 + golang.org/x/mod v0.14.0 + golang.org/x/tools v0.17.0 ) require ( @@ -17,7 +17,7 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/volatiletech/inflect v0.0.1 // indirect - golang.org/x/sys v0.10.0 // indirect - golang.org/x/text v0.9.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index fef84e4..a65f8ee 100644 --- a/go.sum +++ b/go.sum @@ -1,71 +1,55 @@ -github.com/99designs/gqlgen v0.17.35 h1:r0KF1xL3cPMyUArNWeC3e2Ckuc4iiLm7bj5xzYZQYbQ= -github.com/99designs/gqlgen v0.17.35/go.mod h1:Vlf7TeY3ZdVI9SagB5IZE8CYhpq8kJPCVPJ7MrlVoX0= +github.com/99designs/gqlgen v0.17.43 h1:I4SYg6ahjowErAQcHFVKy5EcWuwJ3+Xw9z2fLpuFCPo= +github.com/99designs/gqlgen v0.17.43/go.mod h1:lO0Zjy8MkZgBdv4T1U91x09r0e0WFOdhVUutlQs1Rsc= github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8= github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= -github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g= github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= github.com/friendsofgo/errors v0.9.2 h1:X6NYxef4efCBdwI7BgS820zFaN7Cphrmb+Pljdzjtgk= github.com/friendsofgo/errors v0.9.2/go.mod h1:yCvFW5AkDIL9qn7suHVLiI/gH228n7PC4Pn44IGoTOI= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= -github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= +github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc= -github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= +github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= -github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/sosodev/duration v1.1.0 h1:kQcaiGbJaIsRqgQy7VGlZrVw1giWO+lDoX3MCPnpVO4= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/vektah/gqlparser/v2 v2.5.8 h1:pm6WOnGdzFOCfcQo9L3+xzW51mKrlwTEg4Wr7AH1JW4= -github.com/vektah/gqlparser/v2 v2.5.8/go.mod h1:z8xXUff237NntSuH8mLFijZ+1tjV1swDbpDqjJmk6ME= +github.com/vektah/gqlparser/v2 v2.5.11 h1:JJxLtXIoN7+3x6MBdtIP59TP1RANnY7pXOaDnADQSf8= +github.com/vektah/gqlparser/v2 v2.5.11/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc= github.com/volatiletech/inflect v0.0.1 h1:2a6FcMQyhmPZcLa+uet3VJ8gLn/9svWhJxJYwvE8KsU= github.com/volatiletech/inflect v0.0.1/go.mod h1:IBti31tG6phkHitLlr5j7shC5SOo//x0AjDzaJU1PLA= -github.com/volatiletech/strmangle v0.0.5 h1:CompJPy+lAi9h+YU/IzBR4X2RDRuAuEIP+kjFdyZXcU= -github.com/volatiletech/strmangle v0.0.5/go.mod h1:ycDvbDkjDvhC0NUU8w3fWwl5JEMTV56vTKXzR3GeR+0= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +github.com/volatiletech/strmangle v0.0.6 h1:AdOYE3B2ygRDq4rXDij/MMwq6KVK/pWAYxpC7CLrkKQ= +github.com/volatiletech/strmangle v0.0.6/go.mod h1:ycDvbDkjDvhC0NUU8w3fWwl5JEMTV56vTKXzR3GeR+0= +golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= +golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= -golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= +golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/plugin_convert.go b/plugin_convert.go index 331870c..cc62241 100755 --- a/plugin_convert.go +++ b/plugin_convert.go @@ -23,13 +23,6 @@ import ( var pathRegex *regexp.Regexp //nolint:gochecknoglobals func init() { //nolint:gochecknoinits - fmt.Println(" _ _____ _ _ \n | | | __ \\(_) | | \n __ _____| |__ | |__) |_ __| | __ _ ___ \n \\ \\ /\\ / / _ \\ '_ \\| _ /| |/ _` |/ _` |/ _ \\\n \\ V V / __/ |_) | | \\ \\| | (_| | (_| | __/\n \\_/\\_/ \\___|_.__/|_| \\_\\_|\\__,_|\\__, |\\___|\n __/ | \n |___/ ") //nolint:lll - fmt.Println("") - fmt.Println(" Please help us with feedback, stars and PR's to improve this plugin.") - fmt.Println(" If you don't have time for that, please donate if you like this project.") - fmt.Println(" Click the sponsor button (PayPal) on https://github.com/web-ridge/gqlgen-sqlboiler") - fmt.Println("") - pathRegex = regexp.MustCompile(`src/(.*)`) // Default level for this example is info, unless debug flag is present @@ -151,7 +144,7 @@ func (m *ConvertPlugin) GenerateCode() error { func (m *ConvertPlugin) generateFile(data *ConvertTemplateData, fileName string, userDefinedFunctions []string) { templateName := fileName + "tpl" - log.Debug().Msg("[convert] render " + templateName) + // log.Debug().Msg("[convert] render " + templateName) templateContent, err := getTemplateContent(templateName) if err != nil { @@ -168,7 +161,7 @@ func (m *ConvertPlugin) generateFile(data *ConvertTemplateData, fileName string, }); renderError != nil { log.Err(renderError).Msg("error while rendering " + templateName) } - log.Debug().Msg("[convert] rendered " + templateName) + log.Debug().Msg("[convert] generated " + templateName) } func getTemplateContent(filename string) (string, error) { diff --git a/plugin_resolver.go b/plugin_resolver.go index 6676e21..97c1232 100644 --- a/plugin_resolver.go +++ b/plugin_resolver.go @@ -107,8 +107,8 @@ func (m *ResolverPlugin) generateSingleFile(data *codegen.Data, models []*struct if resolver.Model.BoilerModel != nil && resolver.Model.BoilerModel.Name != "" { file.Resolvers = append(file.Resolvers, resolver) } else if resolver.Field.GoFieldName != "Node" { - log.Debug().Str("resolver", resolver.Object.Name).Str("field", resolver.Field.GoFieldName).Msg( - "skipping resolver since no model found") + // log.Debug().Str("resolver", resolver.Object.Name).Str("field", resolver.Field.GoFieldName).Msg( + // "skipping resolver since no model found") } } } diff --git a/sqlboiler_graphql_schema.go b/sqlboiler_graphql_schema.go index b6ac497..6874c8e 100644 --- a/sqlboiler_graphql_schema.go +++ b/sqlboiler_graphql_schema.go @@ -323,6 +323,7 @@ func SchemaGet( w.tl(field.Name + ": " + getFilterType(field) + "Filter" + directives) } } + w.tl("withDeleted: Boolean") w.tl("or: " + model.Name + "Where") w.tl("and: " + model.Name + "Where") w.l("}") diff --git a/structs/structs.go b/structs/structs.go index 953ad4c..2ba4a5e 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -80,9 +80,10 @@ type Field struct { //nolint:maligned // boiler relation stuff is inside this field BoilerField BoilerField // graphql relation ship can be found here - Relationship *Model - IsOr bool - IsAnd bool + Relationship *Model + IsOr bool + IsAnd bool + IsWithDeleted bool // Some stuff Description string diff --git a/template_files/generated_filter.gotpl b/template_files/generated_filter.gotpl index 1ac6627..ca09e09 100644 --- a/template_files/generated_filter.gotpl +++ b/template_files/generated_filter.gotpl @@ -425,6 +425,10 @@ func TimeUnixFilterToMods(m *{{ $.Frontend.PackageName }}.TimeUnixFilter, c stri if m.And != nil { queryMods = append(queryMods, qm.Expr({{ $field.TypeWithoutPointer|go }}ToMods(m.And, true, "", "")...)) } + {{- else if $field.IsWithDeleted }} + if m.WithDeleted != nil && *m.WithDeleted == true { + queryMods = append(queryMods, qm.WithDeleted()) + } {{- else }} {{- if $field.IsPrimaryID }} if withPrimaryID { diff --git a/templates/templates.go b/templates/templates.go index 761bf13..4db1575 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -78,6 +78,10 @@ func WriteTemplateFile(fileName string, cfg Options) error { } if contentError != nil || writeError != nil || importsError != nil { + // write fallback to file with content that could not be formatted + if err := os.WriteFile(fileName, []byte(content), 0o644); err != nil { + return fmt.Errorf("errors while writing template to %v %v", fileName, err) + } return fmt.Errorf( "errors while writing template to %v writeError: %v, contentError: %v, importError: %v", fileName, writeError, contentError, importsError)