Skip to content

Commit

Permalink
Created the ability to support namespaced queries.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
netikular committed Mar 12, 2024
1 parent 51d1908 commit 9dcabc3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/dato_cms_graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/dato_cms_graphql/graphql_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def initialize_queries
end

def query_name
name.gsub("Query", "")
name.split("::").last.gsub("Query", "")
end

def plural_name
Expand Down
2 changes: 1 addition & 1 deletion lib/dato_cms_graphql/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module DatoCmsGraphql
VERSION = "0.2.1"
VERSION = "0.2.2"
end

0 comments on commit 9dcabc3

Please sign in to comment.