From 8ceba87c1cd95aa3d63d7758b809d4fbdccfb11c Mon Sep 17 00:00:00 2001 From: mununki Date: Sun, 17 Mar 2024 13:50:24 +0900 Subject: [PATCH] fix merging error in reverse order of object extension --- lib/schema.go | 4 ++++ test/object_extension/schema/a.graphql | 7 ++----- test/object_extension/schema/b.graphql | 7 +++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/schema.go b/lib/schema.go index a0ed7f8..4619c5e 100644 --- a/lib/schema.go +++ b/lib/schema.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" "reflect" + "sort" "sync" ) @@ -538,6 +539,9 @@ func (s *Schema) MergeTypeName(wg *sync.WaitGroup) { defer wg.Done() j := 0 seen := make(map[string]struct{}, len(s.Types)) + sort.SliceStable(s.Types, func(i, j int) bool { + return !s.Types[i].Extend && s.Types[j].Extend + }) for _, v := range s.Types { if _, ok := seen[v.Name]; ok { for i := 0; i < j; i++ { diff --git a/test/object_extension/schema/a.graphql b/test/object_extension/schema/a.graphql index 77200ec..6b9a6b4 100644 --- a/test/object_extension/schema/a.graphql +++ b/test/object_extension/schema/a.graphql @@ -1,6 +1,3 @@ -type Person implements Node @talkable{ - id: ID! - createTime: Time! - updateTime: Time! - name: String! +extend type Person @walkable { + hasCar: Boolean! } diff --git a/test/object_extension/schema/b.graphql b/test/object_extension/schema/b.graphql index 6b9a6b4..77200ec 100644 --- a/test/object_extension/schema/b.graphql +++ b/test/object_extension/schema/b.graphql @@ -1,3 +1,6 @@ -extend type Person @walkable { - hasCar: Boolean! +type Person implements Node @talkable{ + id: ID! + createTime: Time! + updateTime: Time! + name: String! }