From 1f81d097efeeca48d20962abbce86d107252aec4 Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Wed, 30 May 2018 20:51:24 +1000 Subject: [PATCH] BC Break: Stop generating foreign keys in models --- codegen/models_build.go | 21 ++------------------- example/dataloader/models_gen.go | 14 -------------- example/dataloader/resolvers.go | 13 ++++++++++++- example/dataloader/types.json | 4 ++++ 4 files changed, 18 insertions(+), 34 deletions(-) create mode 100644 example/dataloader/types.json diff --git a/codegen/models_build.go b/codegen/models_build.go index 8bb7c89a215..211d4bd4aa2 100644 --- a/codegen/models_build.go +++ b/codegen/models_build.go @@ -63,30 +63,13 @@ func (cfg *Config) obj2Model(obj *Object) Model { for i := range obj.Fields { field := &obj.Fields[i] - mf := ModelField{Type: field.Type,GQLName:field.GQLName} + mf := ModelField{Type: field.Type, GQLName: field.GQLName} + mf.GoVarName = ucFirst(field.GQLName) if mf.IsScalar { - mf.GoVarName = ucFirst(field.GQLName) if mf.GoVarName == "Id" { mf.GoVarName = "ID" } - } else if mf.IsInput { - mf.GoVarName = ucFirst(field.GQLName) - } else if mf.IsSlice() { - // one to many, we don't need a prop, we need a resolver - } else { - mf.GoFKName = ucFirst(field.GQLName) + "ID" - mf.GoFKType = "string" - - if obj, ok := cfg.schema.Types[field.GQLType].(*schema.Object); ok { - for _, f := range obj.Fields { - if strings.EqualFold(f.Name, "id") { - if strings.Contains(f.Type.String(), "Int") { - mf.GoFKType = "int" - } - } - } - } } model.Fields = append(model.Fields, mf) diff --git a/example/dataloader/models_gen.go b/example/dataloader/models_gen.go index 1ca77630a28..af1eff551a4 100644 --- a/example/dataloader/models_gen.go +++ b/example/dataloader/models_gen.go @@ -2,25 +2,11 @@ package dataloader -import ( - time "time" -) - type Address struct { ID int `json:"id"` Street string `json:"street"` Country string `json:"country"` } -type Customer struct { - ID int `json:"id"` - Name string `json:"name"` - AddressID int -} type Item struct { Name string `json:"name"` } -type Order struct { - ID int `json:"id"` - Date time.Time `json:"date"` - Amount float64 `json:"amount"` -} diff --git a/example/dataloader/resolvers.go b/example/dataloader/resolvers.go index 0bca84bdecb..f2ab7e5d363 100644 --- a/example/dataloader/resolvers.go +++ b/example/dataloader/resolvers.go @@ -1,4 +1,4 @@ -//go:generate gorunpkg github.com/vektah/gqlgen -out generated.go +//go:generate gorunpkg github.com/vektah/gqlgen -out generated.go -typemap types.json package dataloader @@ -9,6 +9,17 @@ import ( "time" ) +type Customer struct { + ID int `json:"id"` + Name string `json:"name"` + AddressID int +} +type Order struct { + ID int `json:"id"` + Date time.Time `json:"date"` + Amount float64 `json:"amount"` +} + type Resolver struct{} func (r *Resolver) Customer_address(ctx context.Context, it *Customer) (*Address, error) { diff --git a/example/dataloader/types.json b/example/dataloader/types.json new file mode 100644 index 00000000000..3de131fd4a2 --- /dev/null +++ b/example/dataloader/types.json @@ -0,0 +1,4 @@ +{ + "Order": "github.com/vektah/gqlgen/example/dataloader.Order", + "Customer": "github.com/vektah/gqlgen/example/dataloader.Customer" +}