Module: GraphQL::QueryArgument

Defined in:
lib/graphql/query_argument.rb,
lib/graphql/query_argument/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
'0.0.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/graphql/query_argument.rb', line 3

def self.included(base)
  base.extend ClassMethods
  base.instance_eval do
    @config = {
      query_arguments: {}
    }
  end
end

Instance Method Details

#initialize(object:, context:, field:) ⇒ Object



12
13
14
15
16
17
# File 'lib/graphql/query_argument.rb', line 12

def initialize(object:, context:, field:)
  puts field.name.class
  @scope = context[:current_object].send(field.name.underscore)
  @query_arguments = self.class.config[:query_arguments]
  super object: object, context: context, field: field
end

#resolve(**args) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/graphql/query_argument.rb', line 19

def resolve(**args)
  args.inject(@scope) do |scope, (name, value)|
    return scope unless @query_arguments[name]

    instance_exec scope, value, &@query_arguments[name]
  end
end