diff --git a/.golangci.yml b/.golangci.yml index 35451ce469a..a49ca08d2f0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,14 +32,12 @@ linters-settings: - name: blank-imports - name: context-as-argument - name: context-keys-type - - name: dot-imports - name: error-return - name: error-naming - name: exported disabled: true - name: if-return - name: increment-decrement - - name: var-naming - name: var-declaration - name: package-comments disabled: true diff --git a/_examples/starwars/models/generated.go b/_examples/starwars/models/generated.go index 7a3fd230516..4aac19f3672 100644 --- a/_examples/starwars/models/generated.go +++ b/_examples/starwars/models/generated.go @@ -50,20 +50,20 @@ func (Starship) IsSearchResult() {} type Episode string const ( - EpisodeNewhope Episode = "NEWHOPE" - EpisodeEmpire Episode = "EMPIRE" - EpisodeJedi Episode = "JEDI" + EpisodeNEWHOPE Episode = "NEWHOPE" + EpisodeEMPIRE Episode = "EMPIRE" + EpisodeJEDI Episode = "JEDI" ) var AllEpisode = []Episode{ - EpisodeNewhope, - EpisodeEmpire, - EpisodeJedi, + EpisodeNEWHOPE, + EpisodeEMPIRE, + EpisodeJEDI, } func (e Episode) IsValid() bool { switch e { - case EpisodeNewhope, EpisodeEmpire, EpisodeJedi: + case EpisodeNEWHOPE, EpisodeEMPIRE, EpisodeJEDI: return true } return false @@ -93,18 +93,18 @@ func (e Episode) MarshalGQL(w io.Writer) { type LengthUnit string const ( - LengthUnitMeter LengthUnit = "METER" - LengthUnitFoot LengthUnit = "FOOT" + LengthUnitMETER LengthUnit = "METER" + LengthUnitFOOT LengthUnit = "FOOT" ) var AllLengthUnit = []LengthUnit{ - LengthUnitMeter, - LengthUnitFoot, + LengthUnitMETER, + LengthUnitFOOT, } func (e LengthUnit) IsValid() bool { switch e { - case LengthUnitMeter, LengthUnitFoot: + case LengthUnitMETER, LengthUnitFOOT: return true } return false diff --git a/_examples/todo/models_gen.go b/_examples/todo/models_gen.go index 0f2db9c8d08..8f9968c5df4 100644 --- a/_examples/todo/models_gen.go +++ b/_examples/todo/models_gen.go @@ -25,18 +25,18 @@ type TodoInput struct { type Role string const ( - RoleAdmin Role = "ADMIN" - RoleOwner Role = "OWNER" + RoleADMIN Role = "ADMIN" + RoleOWNER Role = "OWNER" ) var AllRole = []Role{ - RoleAdmin, - RoleOwner, + RoleADMIN, + RoleOWNER, } func (e Role) IsValid() bool { switch e { - case RoleAdmin, RoleOwner: + case RoleADMIN, RoleOWNER: return true } return false diff --git a/_examples/type-system-extension/models_gen.go b/_examples/type-system-extension/models_gen.go index c1df9a199be..5559fdb33e8 100644 --- a/_examples/type-system-extension/models_gen.go +++ b/_examples/type-system-extension/models_gen.go @@ -42,18 +42,18 @@ type TodoInput struct { type State string const ( - StateNotYet State = "NOT_YET" - StateDone State = "DONE" + StateNOTYET State = "NOT_YET" + StateDONE State = "DONE" ) var AllState = []State{ - StateNotYet, - StateDone, + StateNOTYET, + StateDONE, } func (e State) IsValid() bool { switch e { - case StateNotYet, StateDone: + case StateNOTYET, StateDONE: return true } return false diff --git a/codegen/testserver/followschema/models-gen.go b/codegen/testserver/followschema/models-gen.go index 5915e039fee..b9e7b2fa9e6 100644 --- a/codegen/testserver/followschema/models-gen.go +++ b/codegen/testserver/followschema/models-gen.go @@ -294,18 +294,18 @@ type IIt struct { type EnumTest string const ( - EnumTestOk EnumTest = "OK" - EnumTestNg EnumTest = "NG" + EnumTestOK EnumTest = "OK" + EnumTestNG EnumTest = "NG" ) var AllEnumTest = []EnumTest{ - EnumTestOk, - EnumTestNg, + EnumTestOK, + EnumTestNG, } func (e EnumTest) IsValid() bool { switch e { - case EnumTestOk, EnumTestNg: + case EnumTestOK, EnumTestNG: return true } return false @@ -335,18 +335,18 @@ func (e EnumTest) MarshalGQL(w io.Writer) { type Status string const ( - StatusOk Status = "OK" - StatusError Status = "ERROR" + StatusOK Status = "OK" + StatusERROR Status = "ERROR" ) var AllStatus = []Status{ - StatusOk, - StatusError, + StatusOK, + StatusERROR, } func (e Status) IsValid() bool { switch e { - case StatusOk, StatusError: + case StatusOK, StatusERROR: return true } return false diff --git a/codegen/testserver/singlefile/models-gen.go b/codegen/testserver/singlefile/models-gen.go index 98e10aa26a3..10474288e92 100644 --- a/codegen/testserver/singlefile/models-gen.go +++ b/codegen/testserver/singlefile/models-gen.go @@ -294,18 +294,18 @@ type IIt struct { type EnumTest string const ( - EnumTestOk EnumTest = "OK" - EnumTestNg EnumTest = "NG" + EnumTestOK EnumTest = "OK" + EnumTestNG EnumTest = "NG" ) var AllEnumTest = []EnumTest{ - EnumTestOk, - EnumTestNg, + EnumTestOK, + EnumTestNG, } func (e EnumTest) IsValid() bool { switch e { - case EnumTestOk, EnumTestNg: + case EnumTestOK, EnumTestNG: return true } return false @@ -335,18 +335,18 @@ func (e EnumTest) MarshalGQL(w io.Writer) { type Status string const ( - StatusOk Status = "OK" - StatusError Status = "ERROR" + StatusOK Status = "OK" + StatusERROR Status = "ERROR" ) var AllStatus = []Status{ - StatusOk, - StatusError, + StatusOK, + StatusERROR, } func (e Status) IsValid() bool { switch e { - case StatusOk, StatusError: + case StatusOK, StatusERROR: return true } return false diff --git a/graphql/handler/transport/websocket.go b/graphql/handler/transport/websocket.go index c35f5212edd..651ccee4820 100644 --- a/graphql/handler/transport/websocket.go +++ b/graphql/handler/transport/websocket.go @@ -193,7 +193,7 @@ func (c *wsConnection) init() bool { } } - var initAckPayload *InitPayload = nil + var initAckPayload *InitPayload if c.InitFunc != nil { var ctx context.Context ctx, initAckPayload, err = c.InitFunc(c.ctx, c.initPayload) diff --git a/integration/server/generated.go b/integration/server/generated.go index 0c54c61b677..e10a0389168 100644 --- a/integration/server/generated.go +++ b/integration/server/generated.go @@ -3198,7 +3198,7 @@ func (ec *executionContext) unmarshalInputDateFilter(ctx context.Context, obj in it.Timezone = data case "op": ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("op")) - data, err := ec.unmarshalODATE_FILTER_OP2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋserverᚋmodelsᚑgoᚐDateFilterOp(ctx, v) + data, err := ec.unmarshalODATE_FILTER_OP2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋserverᚋmodelsᚑgoᚐDATEFILTEROP(ctx, v) if err != nil { return it, err } @@ -4504,16 +4504,16 @@ func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast return res } -func (ec *executionContext) unmarshalODATE_FILTER_OP2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋserverᚋmodelsᚑgoᚐDateFilterOp(ctx context.Context, v interface{}) (*models.DateFilterOp, error) { +func (ec *executionContext) unmarshalODATE_FILTER_OP2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋserverᚋmodelsᚑgoᚐDATEFILTEROP(ctx context.Context, v interface{}) (*models.DATEFILTEROP, error) { if v == nil { return nil, nil } - var res = new(models.DateFilterOp) + var res = new(models.DATEFILTEROP) err := res.UnmarshalGQL(v) return res, graphql.ErrorOnPath(ctx, err) } -func (ec *executionContext) marshalODATE_FILTER_OP2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋserverᚋmodelsᚑgoᚐDateFilterOp(ctx context.Context, sel ast.SelectionSet, v *models.DateFilterOp) graphql.Marshaler { +func (ec *executionContext) marshalODATE_FILTER_OP2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋintegrationᚋserverᚋmodelsᚑgoᚐDATEFILTEROP(ctx context.Context, sel ast.SelectionSet, v *models.DATEFILTEROP) graphql.Marshaler { if v == nil { return graphql.Null } diff --git a/integration/server/models-go/generated.go b/integration/server/models-go/generated.go index acdc10830c0..a369ec21806 100644 --- a/integration/server/models-go/generated.go +++ b/integration/server/models-go/generated.go @@ -11,7 +11,7 @@ import ( type DateFilter struct { Value string `json:"value"` Timezone *string `json:"timezone,omitempty"` - Op *DateFilterOp `json:"op,omitempty"` + Op *DATEFILTEROP `json:"op,omitempty"` } type ListCoercion struct { @@ -24,70 +24,70 @@ type ListCoercion struct { type Query struct { } -type DateFilterOp string +type DATEFILTEROP string const ( - DateFilterOpEq DateFilterOp = "EQ" - DateFilterOpNeq DateFilterOp = "NEQ" - DateFilterOpGt DateFilterOp = "GT" - DateFilterOpGte DateFilterOp = "GTE" - DateFilterOpLt DateFilterOp = "LT" - DateFilterOpLte DateFilterOp = "LTE" + DATEFILTEROPEQ DATEFILTEROP = "EQ" + DATEFILTEROPNEQ DATEFILTEROP = "NEQ" + DATEFILTEROPGT DATEFILTEROP = "GT" + DATEFILTEROPGTE DATEFILTEROP = "GTE" + DATEFILTEROPLT DATEFILTEROP = "LT" + DATEFILTEROPLTE DATEFILTEROP = "LTE" ) -var AllDateFilterOp = []DateFilterOp{ - DateFilterOpEq, - DateFilterOpNeq, - DateFilterOpGt, - DateFilterOpGte, - DateFilterOpLt, - DateFilterOpLte, +var AllDATEFILTEROP = []DATEFILTEROP{ + DATEFILTEROPEQ, + DATEFILTEROPNEQ, + DATEFILTEROPGT, + DATEFILTEROPGTE, + DATEFILTEROPLT, + DATEFILTEROPLTE, } -func (e DateFilterOp) IsValid() bool { +func (e DATEFILTEROP) IsValid() bool { switch e { - case DateFilterOpEq, DateFilterOpNeq, DateFilterOpGt, DateFilterOpGte, DateFilterOpLt, DateFilterOpLte: + case DATEFILTEROPEQ, DATEFILTEROPNEQ, DATEFILTEROPGT, DATEFILTEROPGTE, DATEFILTEROPLT, DATEFILTEROPLTE: return true } return false } -func (e DateFilterOp) String() string { +func (e DATEFILTEROP) String() string { return string(e) } -func (e *DateFilterOp) UnmarshalGQL(v interface{}) error { +func (e *DATEFILTEROP) UnmarshalGQL(v interface{}) error { str, ok := v.(string) if !ok { return fmt.Errorf("enums must be strings") } - *e = DateFilterOp(str) + *e = DATEFILTEROP(str) if !e.IsValid() { return fmt.Errorf("%s is not a valid DATE_FILTER_OP", str) } return nil } -func (e DateFilterOp) MarshalGQL(w io.Writer) { +func (e DATEFILTEROP) MarshalGQL(w io.Writer) { fmt.Fprint(w, strconv.Quote(e.String())) } type ErrorType string const ( - ErrorTypeCustom ErrorType = "CUSTOM" - ErrorTypeNormal ErrorType = "NORMAL" + ErrorTypeCUSTOM ErrorType = "CUSTOM" + ErrorTypeNORMAL ErrorType = "NORMAL" ) var AllErrorType = []ErrorType{ - ErrorTypeCustom, - ErrorTypeNormal, + ErrorTypeCUSTOM, + ErrorTypeNORMAL, } func (e ErrorType) IsValid() bool { switch e { - case ErrorTypeCustom, ErrorTypeNormal: + case ErrorTypeCUSTOM, ErrorTypeNORMAL: return true } return false diff --git a/internal/code/imports.go b/internal/code/imports.go index 89ebab9625f..e950f1d5af9 100644 --- a/internal/code/imports.go +++ b/internal/code/imports.go @@ -102,21 +102,21 @@ func goModuleRoot(dir string) (string, bool) { // go.mod is not found in the tree, so the same sentinel value fits all the directories in a tree goModuleRootCache[d] = result } else { - if relPath, err := filepath.Rel(result.goModPath, d); err != nil { + relPath, err := filepath.Rel(result.goModPath, d) + if err != nil { panic(err) - } else { - path := result.moduleName - relPath := filepath.ToSlash(relPath) - if !strings.HasSuffix(relPath, "/") { - path += "/" - } - path += relPath - - goModuleRootCache[d] = goModuleSearchResult{ - path: path, - goModPath: result.goModPath, - moduleName: result.moduleName, - } + } + path := result.moduleName + relPath = filepath.ToSlash(relPath) + if !strings.HasSuffix(relPath, "/") { + path += "/" + } + path += relPath + + goModuleRootCache[d] = goModuleSearchResult{ + path: path, + goModPath: result.goModPath, + moduleName: result.moduleName, } } } diff --git a/plugin/modelgen/models.go b/plugin/modelgen/models.go index ed9f21fc74b..5f6ce94e930 100644 --- a/plugin/modelgen/models.go +++ b/plugin/modelgen/models.go @@ -292,18 +292,17 @@ func (m *Plugin) MutateConfig(cfg *config.Config) error { getter += "\treturn interfaceSlice\n" getter += "}" return getter - } else { - getter := fmt.Sprintf("func (this %s) Get%s() %s { return ", templates.ToGo(model.Name), field.GoName, goType) - - if interfaceFieldTypeIsPointer && !structFieldTypeIsPointer { - getter += "&" - } else if !interfaceFieldTypeIsPointer && structFieldTypeIsPointer { - getter += "*" - } + } + getter := fmt.Sprintf("func (this %s) Get%s() %s { return ", templates.ToGo(model.Name), field.GoName, goType) - getter += fmt.Sprintf("this.%s }", field.GoName) - return getter + if interfaceFieldTypeIsPointer && !structFieldTypeIsPointer { + getter += "&" + } else if !interfaceFieldTypeIsPointer && structFieldTypeIsPointer { + getter += "*" } + + getter += fmt.Sprintf("this.%s }", field.GoName) + return getter } funcMap := template.FuncMap{ "getInterfaceByName": getInterfaceByName,