Skip to content

Commit

Permalink
Yep, there was a problem with unique-ing by name
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
netikular committed Mar 12, 2024
1 parent 9dcabc3 commit 8ca65cd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/dato_cms_graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8ca65cd

Please sign in to comment.