2021-04-17 20:07:23 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Graphql
|
|
|
|
module ResolverFactories
|
|
|
|
def new_resolver(resolved_value = 'Resolved value', method: :resolve)
|
|
|
|
case method
|
|
|
|
when :resolve
|
|
|
|
simple_resolver(resolved_value)
|
|
|
|
when :find_object
|
|
|
|
find_object_resolver(resolved_value)
|
|
|
|
else
|
|
|
|
raise "Cannot build a resolver for #{method}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
def simple_resolver(resolved_value = 'Resolved value', base_class: Resolvers::BaseResolver)
|
|
|
|
Class.new(base_class) do
|
2021-04-17 20:07:23 +05:30
|
|
|
define_method :resolve do |**_args|
|
|
|
|
resolved_value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_object_resolver(resolved_value = 'Found object')
|
|
|
|
Class.new(Resolvers::BaseResolver) do
|
|
|
|
include ::Gitlab::Graphql::Authorize::AuthorizeResource
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
def resolve(...)
|
|
|
|
authorized_find!(...)
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
define_method :find_object do |**_args|
|
|
|
|
resolved_value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|