9b65d4bb41
- All definitions have been replaced by classes: http://graphql-ruby.org/schema/class_based_api.html - Authorization & Presentation have been refactored to work in the class based system - Loaders have been replaced by resolvers - Times are now coersed as ISO 8601
25 lines
745 B
Ruby
25 lines
745 B
Ruby
module Gitlab
|
|
module Graphql
|
|
module Present
|
|
class Instrumentation
|
|
def instrument(type, field)
|
|
presented_in = field.metadata[:type_class].owner
|
|
return field unless presented_in.respond_to?(:presenter_class)
|
|
return field unless presented_in.presenter_class
|
|
|
|
old_resolver = field.resolve_proc
|
|
|
|
resolve_with_presenter = -> (presented_type, args, context) do
|
|
object = presented_type.object
|
|
presenter = presented_in.presenter_class.new(object, **context.to_h)
|
|
old_resolver.call(presenter, args, context)
|
|
end
|
|
|
|
field.redefine do
|
|
resolve(resolve_with_presenter)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|