From 8ca65cde3c1f34e8dc784409c10706b65492d2e1 Mon Sep 17 00:00:00 2001 From: Kevin Pratt Date: Tue, 12 Mar 2024 15:43:37 -0600 Subject: [PATCH] Yep, there was a problem with unique-ing by name The class would change, and we would have no way of knowing if it was the correct version. Instead I added code that will group them by name, then find the most recent one by using `#object_id` The documentation says that no two objects would ever have the same `object_id` lets test that theory. --- lib/dato_cms_graphql.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/dato_cms_graphql.rb b/lib/dato_cms_graphql.rb index ebc81ba..67fbc39 100644 --- a/lib/dato_cms_graphql.rb +++ b/lib/dato_cms_graphql.rb @@ -54,7 +54,10 @@ def self.queries raise "\"#{@path_to_queries}\" does not exist" unless File.exist?(@path_to_queries) Dir[File.join(@path_to_queries, "*.rb")].sort.each { require(_1) } - ObjectSpace.each_object(::Class).select { |klass| klass < DatoCmsGraphql::GraphqlBase }.uniq(&:name) + ObjectSpace.each_object(::Class) + .select { |klass| klass < DatoCmsGraphql::GraphqlBase } + .group_by(&:name).values.map { |values| values.max_by(&:object_id) } + .flatten end def self.path_to_queries=(value)