Skip to content

Commit f3d62cb

Browse files
committed
Fix class method .sync_lazy
1 parent 4e51a23 commit f3d62cb

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

lib/graphql/execution/execute.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def continue_or_wait(raw_value, field_type, field_ctx)
146146
field_ctx.value = Execution::Lazy.new {
147147
inner_value = begin
148148
begin
149-
field_ctx.schema.sync_lazy(raw_value)
149+
field_ctx.schema.sync_lazy(raw_value, field_ctx.query.context)
150150
rescue GraphQL::UnauthorizedError => err
151151
field_ctx.schema.unauthorized_object(err)
152152
end

lib/graphql/field.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def build_default_resolver
323323

324324
module DefaultLazyResolve
325325
def self.call(obj, args, ctx)
326-
ctx.schema.sync_lazy(obj)
326+
ctx.schema.sync_lazy(obj, ctx.query.context)
327327
end
328328
end
329329
end

lib/graphql/schema.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,9 +1017,10 @@ def after_lazy(value)
10171017

10181018
# Override this method to handle lazy objects in a custom way.
10191019
# @param value [Object] an instance of a class registered with {.lazy_resolve}
1020+
# @param ctx [GraphQL::Query::Context] the context for this query
10201021
# @return [Object] A GraphQL-ready (non-lazy) object
1021-
def sync_lazy(value)
1022-
lazy_method = lazy_method_name(value)
1022+
def self.sync_lazy(value, ctx)
1023+
lazy_method = ctx.schema.lazy_method_name(value)
10231024
if lazy_method
10241025
synced_value = value.public_send(lazy_method)
10251026
sync_lazy(synced_value)
@@ -1028,6 +1029,12 @@ def sync_lazy(value)
10281029
end
10291030
end
10301031

1032+
# @see Schema.sync_lazy for a hook to override
1033+
# @api private
1034+
def sync_lazy(value, ctx)
1035+
self.class.sync_lazy(value, ctx)
1036+
end
1037+
10311038
protected
10321039

10331040
def rescues?

0 commit comments

Comments
 (0)