Skip to content

Commit

Permalink
Add check for obviously different TypeReferences (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
zannen committed Nov 11, 2019
1 parent fb96756 commit 3b5df4c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion codegen/type.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
package codegen

import (
"fmt"

"github.com/99designs/gqlgen/codegen/config"
)

func (b *builder) buildTypes() map[string]*config.TypeReference {
ret := map[string]*config.TypeReference{}
var key string
var existing *config.TypeReference
var found bool

for _, ref := range b.Binder.References {
for ref != nil {
ret[ref.UniquenessKey()] = ref
key = ref.UniquenessKey()
if existing, found = ret[key]; found {
// Simplistic check of content which is obviously different.
existingGQL := fmt.Sprintf("%v", existing.GQL)
newGQL := fmt.Sprintf("%v", ref.GQL)
if existingGQL != newGQL {
panic(fmt.Sprintf("non-unique key \"%s\", trying to replace %s with %s", key, existingGQL, newGQL))
}
}
ret[key] = ref

ref = ref.Elem()
}
Expand Down

0 comments on commit 3b5df4c

Please sign in to comment.