Skip to content

Commit beff0d0

Browse files
committed
Try dynamic visibility ...
1 parent aba2c68 commit beff0d0

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

lib/graphql/schema/member/base_dsl_methods.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,6 @@ def default_relay
134134
false
135135
end
136136

137-
def freeze_schema
138-
freeze
139-
end
140-
141137
protected
142138

143139
attr_writer :default_graphql_name, :graphql_name

lib/graphql/schema/ractor_shareable.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def freeze_schema
3838
@frozen_directives = Ractor.make_shareable(directives)
3939

4040
Ractor.make_shareable(visibility)
41+
visibility.types.each do |_name, type_defn|
42+
type_defn.freeze
43+
end
4144
Ractor.make_shareable(introspection_system)
4245
extend(FrozenMethods)
4346

lib/graphql/schema/visibility.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def initialize(schema, dynamic:, preload:, profiles:, migration_errors:)
3232
Visibility::Profile
3333
end
3434
@preload = preload
35+
@preloaded = false
3536
@profiles = profiles
3637
@cached_profiles = {}
3738
@dynamic = dynamic
@@ -46,6 +47,7 @@ def initialize(schema, dynamic:, preload:, profiles:, migration_errors:)
4647
end
4748

4849
def freeze
50+
load_all
4951
@visit = nil
5052
@interface_type_memberships.default_proc = nil
5153
@all_references.default_proc = nil
@@ -72,11 +74,17 @@ def get_type(type_name)
7274
@types[type_name]
7375
end
7476

77+
attr_accessor :types
78+
7579
def preload?
7680
@preload
7781
end
7882

7983
def preload
84+
if @preloaded
85+
raise "Invariant: can't preload twice"
86+
end
87+
@preloaded = true
8088
# Traverse the schema now (and in the *_configured hooks below)
8189
# To make sure things are loaded during boot
8290
@preloaded_types = Set.new
@@ -207,6 +215,7 @@ def ensure_all_loaded(types_to_visit)
207215
end
208216

209217
def load_all(types: nil)
218+
return if frozen?
210219
if @visit.nil?
211220
# Set up the visit system
212221
@interface_type_memberships = Hash.new { |h, interface_type| h[interface_type] = [] }.compare_by_identity

spec/graphql/schema/ractor_shareable_spec.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ class Query < GraphQL::Schema::Object
88
field :i, Int, fallback_value: 1
99
end
1010
query(Query)
11-
validate_timeout(nil) # Timeout doesn't support Ractor yet?
12-
use GraphQL::Schema::Visibility, preload: true, dynamic: false, profiles: {
13-
nil => {}
14-
}
11+
validate_timeout(nil) # Timeout doesn't work in non-main Ractors
12+
use GraphQL::Schema::Visibility, preload: true, profiles: { nil => {} }
1513

1614
extend GraphQL::Schema::RactorShareable
1715
end
@@ -24,13 +22,29 @@ class Query < GraphQL::Schema::Object
2422
result = query.result.to_h
2523
parent.send(result)
2624
rescue StandardError => err
25+
puts err.message
26+
puts err.backtrace
2727
parent.send(err)
2828
end
2929
ractor.send(Ractor.current)
3030
assert_equal "GraphQL::Query", Ractor.receive
3131
assert_equal({"data" => {"__typename" => "Query"}}, Ractor.receive)
3232
end
3333

34+
it "can get schema members by name" do
35+
skip "Doesn't work yet"
36+
ractor = Ractor.new do
37+
parent = Ractor.receive
38+
parent.send(RactorExampleSchema.get_field("Query", "__typename").class.name)
39+
rescue StandardError => err
40+
puts err.message
41+
puts err.backtrace
42+
parent.send(err)
43+
end
44+
ractor.send(Ractor.current)
45+
assert_equal "GraphQL::Field", Ractor.receive
46+
end
47+
3448
it "can parse a schema string to ast" do
3549
schema_str = Dummy::Schema.to_definition
3650
ractor = Ractor.new do

0 commit comments

Comments
 (0)