lib/rails/graphql/request/component/field.rb in rails-graphql-1.0.0.beta vs lib/rails/graphql/request/component/field.rb in rails-graphql-1.0.0.rc1
- old
+ new
@@ -13,11 +13,11 @@
include SelectionSet
include Directives
delegate :decorate, to: :type_klass
delegate :operation, :variables, :request, to: :parent
- delegate :method_name, :resolver, :performer, :type_klass,:leaf_type?,
+ delegate :method_name, :resolver, :performer, :type_klass, :leaf_type?,
:dynamic_resolver?, :mutation?, to: :field
attr_reader :name, :alias_name, :parent, :field, :arguments, :current_object
alias args arguments
@@ -95,14 +95,15 @@
# A little helper for finding the correct parent type name
def typename
(try(:current_object) || try(:type_klass))&.gql_name
end
- # Check if the field is an entry point, meaning that its parent is the
- # operation and it is associated to a schema field
+ # Check if the field is an entry point, meaning that it is attached to
+ # an owner that has Schema Fields
def entry_point?
- parent.kind === :operation
+ return @entry_point if defined?(@entry_point)
+ @entry_point = field.entry_point?
end
# Fields are assignable because they are actually the selection, so they
# need to be assigned to a filed
def assignable?
@@ -115,10 +116,16 @@
value = field.broadcastable?
value = schema.config.default_subscription_broadcastable if value.nil?
value != false
end
+ # Override this to also check if the key would be added to the response
+ # again
+ def skipped?
+ super || response.key?(gql_name)
+ end
+
# A little extension of the +is_a?+ method that allows checking it using
# the underlying +field+
def of_type?(klass)
super || field.of_type?(klass)
end
@@ -148,10 +155,11 @@
ensure
@field, @current_object = old_field, nil
end
# Build the cache object
+ # TODO: Add the arguments into the GID, but the problem is variables
def cache_dump
super.merge(field: (field && all_to_gid(field)))
end
# Organize from cache data
@@ -170,14 +178,14 @@
def organize_then(&block)
super(block) do
check_assignment!
parse_directives(@node[3])
- check_authorization!
-
parse_arguments(@node[2])
parse_selection(@node[4])
+
+ check_authorization!
end
end
# Perform the prepare step
def prepare_then(&block)
@@ -219,11 +227,10 @@
end
# Check if the field was assigned correctly to an output field
def check_assignment!
raise MissingFieldError, (+<<~MSG).squish if field.nil?
- Unable to find a field named "#{gql_name}" on
- #{entry_point? ? operation.kind : parent.type_klass.name}.
+ Unable to find a field named "#{gql_name}" on #{parent.typename}.
MSG
raise FieldError, (+<<~MSG).squish unless field.output_type?
The "#{gql_name}" was assigned to a non-output type of field: #{field.inspect}.
MSG