Skip to content

Commit

Permalink
Strip any non alphanum characters from interfaces names in modelgen
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Feb 17, 2020
1 parent 7cac361 commit 2675f21
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion example/federation/accounts/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/federation/products/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/federation/reviews/graph/model/models.go
Expand Up @@ -4,7 +4,7 @@ type Product struct {
Upc string `json:"upc"`
}

func (Product) Is_Entity() {}
func (Product) IsEntity() {}

type Review struct {
Body string
Expand All @@ -16,4 +16,4 @@ type User struct {
ID string `json:"id"`
}

func (User) Is_Entity() {}
func (User) IsEntity() {}
2 changes: 1 addition & 1 deletion plugin/federation/fedruntime/runtime.go
Expand Up @@ -9,5 +9,5 @@ type Service struct {

// Everything with a @key implements this
type Entity interface {
Is_Entity()
IsEntity()
}
6 changes: 5 additions & 1 deletion plugin/modelgen/models.go
Expand Up @@ -3,6 +3,7 @@ package modelgen
import (
"fmt"
"go/types"
"regexp"
"sort"

"github.com/99designs/gqlgen/codegen/config"
Expand Down Expand Up @@ -71,6 +72,8 @@ func (m *Plugin) Name() string {
return "modelgen"
}

var nonAlphaNum = regexp.MustCompile("[^a-zA-Z0-9]+")

func (m *Plugin) MutateConfig(cfg *config.Config) error {
binder := cfg.NewBinder()

Expand Down Expand Up @@ -99,8 +102,9 @@ func (m *Plugin) MutateConfig(cfg *config.Config) error {
Description: schemaType.Description,
Name: schemaType.Name,
}

for _, implementor := range cfg.Schema.GetImplements(schemaType) {
it.Implements = append(it.Implements, implementor.Name)
it.Implements = append(it.Implements, nonAlphaNum.ReplaceAllLiteralString(implementor.Name, ""))
}

for _, field := range schemaType.Fields {
Expand Down

0 comments on commit 2675f21

Please sign in to comment.