From 9dcabc350a8899dc361ce3d3cd62ed923ccf2bbb Mon Sep 17 00:00:00 2001 From: Kevin Pratt Date: Tue, 12 Mar 2024 15:25:01 -0600 Subject: [PATCH] Created the ability to support namespaced queries. This was needed incase the user put the queries in a subfolder. It will pull the last class name off and use that as the query name. So Queries::MyModule::Profile will expect the datocms model to be named "Profile". Same with the rails intergation, the model will still be "Profile" none of the other stuff matters at this time. Also ran into an issue in Bridgetown where the classes were being re-created over and over again. I put in a unique clause into the search for query names so that it would clear things up. Just realized that this may cause a problem.... Investigating now. --- lib/dato_cms_graphql.rb | 2 +- lib/dato_cms_graphql/graphql_base.rb | 2 +- lib/dato_cms_graphql/version.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/dato_cms_graphql.rb b/lib/dato_cms_graphql.rb index 529718d..ebc81ba 100644 --- a/lib/dato_cms_graphql.rb +++ b/lib/dato_cms_graphql.rb @@ -54,7 +54,7 @@ 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 } + ObjectSpace.each_object(::Class).select { |klass| klass < DatoCmsGraphql::GraphqlBase }.uniq(&:name) end def self.path_to_queries=(value) diff --git a/lib/dato_cms_graphql/graphql_base.rb b/lib/dato_cms_graphql/graphql_base.rb index 5e8013b..018d149 100644 --- a/lib/dato_cms_graphql/graphql_base.rb +++ b/lib/dato_cms_graphql/graphql_base.rb @@ -34,7 +34,7 @@ def initialize_queries end def query_name - name.gsub("Query", "") + name.split("::").last.gsub("Query", "") end def plural_name diff --git a/lib/dato_cms_graphql/version.rb b/lib/dato_cms_graphql/version.rb index d5e172a..ba2cee3 100644 --- a/lib/dato_cms_graphql/version.rb +++ b/lib/dato_cms_graphql/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module DatoCmsGraphql - VERSION = "0.2.1" + VERSION = "0.2.2" end