Skip to content

Commit bb73923

Browse files
committed
Set context[:current_field] in testing helpers
1 parent 2c10917 commit bb73923

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/graphql/testing/helpers.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def run_graphql_field(schema, field_path, object, arguments: {}, context: {}, as
5555
visible_field = dummy_query.types.field(object_type, field_name) # rubocop:disable Development/ContextIsPassedCop
5656
if visible_field
5757
dummy_query.context.dataloader.run_isolated {
58+
query_context[:current_field] = visible_field
5859
field_args = visible_field.coerce_arguments(graphql_result, arguments, query_context)
5960
field_args = schema.sync_lazy(field_args)
6061
if visible_field.extras.any?

spec/graphql/testing/helpers_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ def authorized?(obj, args, ctx)
7272
ctx[:current_user]&.admin?
7373
end
7474
end
75+
76+
field :current_field, String
77+
78+
def current_field
79+
context[:current_field].path
80+
end
7581
end
7682

7783
class Query < GraphQL::Schema::Object
@@ -143,6 +149,7 @@ def self.resolve_type(abs_t, obj, ctx)
143149
with_resolution_context(AssertionsSchema, object: { name: "Foo" }, type: "Student", context: { admin_for: ["Foo"] }) do |rc|
144150
rc.run_graphql_field("name")
145151
rc.run_graphql_field("isAdminFor")
152+
assert_equal "Student.currentField", rc.run_graphql_field("currentField")
146153
end
147154
end
148155

0 commit comments

Comments
 (0)