Skip to content

Commit

Permalink
Merge pull request 99designs#900 from zannen/master
Browse files Browse the repository at this point in the history
Update UniquenessKey for when Element is/isn't nullable (99designs#896)
  • Loading branch information
vektah authored Nov 11, 2019
2 parents f6d3d82 + 47f53e8 commit 587344b
Show file tree
Hide file tree
Showing 17 changed files with 649 additions and 302 deletions.
7 changes: 6 additions & 1 deletion codegen/config/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,12 @@ func (t *TypeReference) UniquenessKey() string {
nullability = "N"
}

return nullability + t.Definition.Name + "2" + templates.TypeIdentifier(t.GO)
var elemNullability = ""
if t.GQL.Elem != nil && t.GQL.Elem.NonNull {
// Fix for #896
elemNullability = "ᚄ"
}
return nullability + t.Definition.Name + "2" + templates.TypeIdentifier(t.GO) + elemNullability
}

func (t *TypeReference) MarshalFunc() string {
Expand Down
372 changes: 332 additions & 40 deletions codegen/testserver/generated.go

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions codegen/testserver/issue896.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This example should build stable output. If the file content starts
# alternating nondeterministically between two outputs, then see
# https://github.com/99designs/gqlgen/issues/896.

extend schema {
query: Query
subscription: Subscription
}

type CheckIssue896 {id: Int}

extend type Query {
issue896a: [CheckIssue896!] # Note the "!" or lack thereof.
}

extend type Subscription {
issue896b: [CheckIssue896] # Note the "!" or lack thereof.
}
4 changes: 4 additions & 0 deletions codegen/testserver/models-gen.go

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

6 changes: 6 additions & 0 deletions codegen/testserver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ func (r *queryResolver) Shapes(ctx context.Context) ([]Shape, error) {
func (r *queryResolver) NoShape(ctx context.Context) (Shape, error) {
panic("not implemented")
}
func (r *queryResolver) Issue896a(ctx context.Context) ([]*CheckIssue896, error) {
panic("not implemented")
}
func (r *queryResolver) MapStringInterface(ctx context.Context, in map[string]interface{}) (map[string]interface{}, error) {
panic("not implemented")
}
Expand Down Expand Up @@ -263,6 +266,9 @@ func (r *subscriptionResolver) DirectiveDouble(ctx context.Context) (<-chan *str
func (r *subscriptionResolver) DirectiveUnimplemented(ctx context.Context) (<-chan *string, error) {
panic("not implemented")
}
func (r *subscriptionResolver) Issue896b(ctx context.Context) (<-chan []*CheckIssue896, error) {
panic("not implemented")
}

type userResolver struct{ *Resolver }

Expand Down
8 changes: 8 additions & 0 deletions codegen/testserver/stub.go

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

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
42 changes: 21 additions & 21 deletions example/chat/generated.go

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

Loading

0 comments on commit 587344b

Please sign in to comment.