class GraphQL::Schema::Directive::Transform
}
username @transform(by: “upcase”)
viewer {
@example Transforming strings
end
directive(GraphQL::Schema::Directive::Transform)
class MySchema < GraphQL::Schema
@example Installing the directive
it’s applied by calling a method with that name.
and if the named transform is whitelisted and applies to the return value,
This directive takes the return value of the tagged part of the query,
An example directive to show how you might interact with the runtime.
def self.resolve(object, arguments, context)
def self.resolve(object, arguments, context) path = context.namespace(:interpreter)[:current_path] return_value = yield transform_name = arguments[:by] if TRANSFORMS.include?(transform_name) && return_value.respond_to?(transform_name) return_value = return_value.public_send(transform_name) response = context.namespace(:interpreter)[:runtime].final_result *keys, last = path keys.each do |key| if response && (response = response[key]) next else break end end if response response[last] = return_value end nil end end