Skip to content

Commit aba2c68

Browse files
committed
Support validation in non-main ractors
1 parent 020bb21 commit aba2c68

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/graphql/static_validation/rules/unique_directives_per_location.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ module UniqueDirectivesPerLocation
1919
:on_field,
2020
]
2121

22-
DIRECTIVE_NODE_HOOKS.each do |method_name|
23-
define_method(method_name) do |node, parent|
22+
VALIDATE_DIRECTIVE_LOCATION_ON_NODE = <<~RUBY
23+
def %{method_name}(node, parent)
2424
if !node.directives.empty?
2525
validate_directive_location(node)
2626
end
2727
super(node, parent)
2828
end
29+
RUBY
30+
DIRECTIVE_NODE_HOOKS.each do |method_name|
31+
# Can't use `define_method {...}` here because the proc can't be isolated for use in non-main Ractors
32+
module_eval(VALIDATE_DIRECTIVE_LOCATION_ON_NODE % { method_name: method_name }) # rubocop:disable Development/NoEvalCop
2933
end
3034

3135
private

spec/graphql/schema/ractor_shareable_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ class Query < GraphQL::Schema::Object
1717
end
1818

1919
it "can access some basic GraphQL objects" do
20-
2120
ractor = Ractor.new do
2221
parent = Ractor.receive
23-
query = GraphQL::Query.new(RactorExampleSchema, "{ __typename}", validate: false )
22+
query = GraphQL::Query.new(RactorExampleSchema, "{ __typename }" )
2423
parent.send(query.class.name)
2524
result = query.result.to_h
2625
parent.send(result)
26+
rescue StandardError => err
27+
parent.send(err)
2728
end
2829
ractor.send(Ractor.current)
2930
assert_equal "GraphQL::Query", Ractor.receive

0 commit comments

Comments
 (0)