Skip to content

Commit

Permalink
Temporarily fix the merger not returning correctly for Unions
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinmo-splunk committed Aug 8, 2019
1 parent 4874e3a commit c37d4ef
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func mergeSchemas(sources []*ast.Schema) (*ast.Schema, error) {
Directives: map[string]*ast.DirectiveDefinition{},
}

unionSet := map[string]bool{}

// merging the schemas has to happen in 2 passes per definnition. The first groups definitions into different
// categories. Interfaces need to be validated before we can add the types that implement them
types := map[string][]*ast.Definition{}
Expand Down Expand Up @@ -92,8 +94,19 @@ func mergeSchemas(sources []*ast.Schema) (*ast.Schema, error) {
// use the declaration that we got from the new schema
result.Types[name] = definition

// register the type as an implementer of itself
result.AddPossibleType(name, definition)
if definition.Kind == ast.Union {
for _, possibleType := range definition.Types {
for _, typedef := range types[possibleType] {
if _, exists := unionSet[typedef.Name]; !exists {
unionSet[typedef.Name] = true
result.AddPossibleType(name, typedef)
}
}
}
} else {
// register the type as an implementer of itself
result.AddPossibleType(name, definition)
}

// each interface that this type implements needs to be registered
for _, iface := range definition.Interfaces {
Expand Down

0 comments on commit c37d4ef

Please sign in to comment.