Skip to content

Commit 655a634

Browse files
authored
Merge pull request #5353 from rmosolgo/partial-operation-name
Add Partial#selected_operation_name
2 parents 9c78dd9 + 26bb910 commit 655a634

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/graphql/query/partial.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ def selected_operation
151151
def static_errors
152152
@query.static_errors
153153
end
154+
155+
def selected_operation_name
156+
@query.selected_operation_name
157+
end
154158
end
155159
end
156160
end

spec/graphql/query/partial_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ def read_context(key:)
110110
def current_path
111111
context.current_path
112112
end
113+
114+
field :current_values, [String]
115+
def current_values
116+
[
117+
GraphQL::Current.operation_name,
118+
GraphQL::Current.field.path,
119+
GraphQL::Current.dataloader_source_class.inspect,
120+
]
121+
end
113122
end
114123

115124
class Mutation < GraphQL::Schema::Object
@@ -165,6 +174,11 @@ def run_partials(string, partial_configs, **query_kwargs)
165174
], results
166175
end
167176

177+
it "works with GraphQL::Current" do
178+
res = run_partials("query CheckCurrentValues { query { currentValues } }", [path: ["query"], object: nil])
179+
assert_equal ["CheckCurrentValues", "Query.currentValues", "nil"], res[0]["data"]["currentValues"]
180+
end
181+
168182
it "returns errors if they occur" do
169183
str = "{
170184
farm1: farm(id: \"1\") { error }

0 commit comments

Comments
 (0)