Sha256: d9c21d6f9942c6ca88e57a4f10edaf5a99582f8b1e8bdfbb62d1cc565a01f951

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module GraphQL
  module Sugar
    module Define
      module Resolver
        def self.call(type_defn, field_name, type_or_field = nil, desc = nil, **kwargs, &block) # rubocop:disable Metrics/ParameterLists
          # Automatically determine type
          type_or_field ||= kwargs[:type] if !kwargs[:type].nil?
          type_or_field ||= Sugar.get_resolver_graphql_type(field_name)

          # Automatically determine if plural, modify type to !types[Type] if true
          plural = kwargs[:plural]
          plural = Sugar.get_resolver_plural(field_name) if plural.nil?
          type_or_field = type_or_field.to_list_type.to_non_null_type if plural

          # Automatically determine function
          function_class = Sugar.get_resolver_function(field_name)
          kwargs[:function] ||= function_class.new
          kwargs[:resolve] ||= ->(obj, args, ctx) { function_class.new.call(obj, args, ctx) }

          GraphQL::Define::AssignObjectField.call(type_defn, field_name, type_or_field, desc, **kwargs, &block)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphql-sugar-0.1.1 lib/graphql/sugar/define/resolver.rb