Skip to content

Commit

Permalink
Several fixes and tests for alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
crashtech committed Feb 3, 2024
1 parent ad068e6 commit f23f627
Show file tree
Hide file tree
Showing 7 changed files with 478 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/rails/graphql/alternative.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Alternative

autoload_at "#{__dir__}/alternative/field_set" do
autoload :FieldSet
autoload :QuerySet
autoload :MutationSet
autoload :SubscriptionSet
end
Expand Down
6 changes: 3 additions & 3 deletions lib/rails/graphql/alternative/field_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FieldSet

include Helpers::Instantiable

self.field_type = Field::OutputField
self.field_type = GraphQL::Field::OutputField
self.valid_field_types = Type::Object.valid_field_types

def self.i18n_scope
Expand All @@ -33,15 +33,15 @@ def self.inspect
#
# Same as a +FieldSet+ but for mutation fields
MutationSet = Class.new(FieldSet)
MutationSet.field_type = Field::MutationField
MutationSet.field_type = GraphQL::Field::MutationField
MutationSet.redefine_singleton_method(:i18n_scope) { :mutation }


# = GraphQL Alternative Subscription Set
#
# Same as a +FieldSet+ but for subscription fields
SubscriptionSet = Class.new(FieldSet)
SubscriptionSet.field_type = Field::SubscriptionField
SubscriptionSet.field_type = GraphQL::Field::SubscriptionField
SubscriptionSet.redefine_singleton_method(:i18n_scope) { :subscription }
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/graphql/alternative/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def inherited(subclass)
def define_field(field_name = nil, type = :any, **xargs, &block)
field_name ||= anonymous? ? '_anonymous' : begin
type_module = type_field_class.to_s.classify.pluralize
user_name = name.split(+"#{type_module}::")[1]
user_name = name.split(+"#{type_module}::")&.at(1)
user_name ||= name.delete_prefix('GraphQL::')
user_name.tr(':', '')
end
Expand Down
8 changes: 4 additions & 4 deletions lib/rails/graphql/helpers/with_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,19 @@ def enabled_fields
def import(source)
# Import an alternative declaration of a field
if source.is_a?(Module) && source <= Alternative::Query
return proxy_field(type, source.field)
return proxy_field(source.field)
end

case source
when Array
# Import a list of fields
source.each { |field| proxy_field(type, field) }
source.each { |field| proxy_field(field) }
when Hash, Concurrent::Map
# Import a keyed list of fields
source.each_value { |field| proxy_field(type, field) }
source.each_value { |field| proxy_field(field) }
when Helpers::WithFields
# Import a set of fields
source.fields.each_value { |field| proxy_field(type, field) }
source.fields.each_value { |field| proxy_field(field) }
else
return if GraphQL.config.silence_import_warnings
GraphQL.logger.warn(+"Unable to import #{source.inspect} into #{self.name}.")
Expand Down
2 changes: 1 addition & 1 deletion lib/rails/graphql/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.version
module VERSION
MAJOR = 1
MINOR = 0
TINY = 1
TINY = 2
PRE = nil

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
Expand Down
Loading

0 comments on commit f23f627

Please sign in to comment.