Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Oct 3, 2024
1 parent 37f5081 commit 122272d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
25 changes: 24 additions & 1 deletion lib/graphql/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,30 @@ def warden
with_prepared_ast { @warden }
end

def_delegators :warden, :get_type, :get_field, :possible_types, :root_type_for_operation
def get_type(type_name)
types.type(type_name) # rubocop:disable Development/ContextIsPassedCop
end

def get_field(owner, field_name)
types.field(owner, field_name) # rubocop:disable Development/ContextIsPassedCop
end

def possible_types(type)
types.possible_types(type) # rubocop:disable Development/ContextIsPassedCop
end

def root_type_for_operation(op_type)
case op_type
when "query"
types.query_root # rubocop:disable Development/ContextIsPassedCop
when "mutation"
types.mutation_root # rubocop:disable Development/ContextIsPassedCop
when "subscription"
types.subscription_root # rubocop:disable Development/ContextIsPassedCop
else
raise ArgumentError, "unexpected root type name: #{op_type.inspect}; expected 'query', 'mutation', or 'subscription'"
end
end

def types
@schema_subset || warden.schema_subset
Expand Down
9 changes: 6 additions & 3 deletions lib/graphql/schema/always_visible.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# frozen_string_literal: true
module GraphQL
class Schema
class AlwaysVisible
module AlwaysVisible
def self.use(schema, **opts)
schema.warden_class = GraphQL::Schema::Warden::NullWarden
schema.subset_class = GraphQL::Schema::Warden::NullWarden::NullSubset
schema.extend(self)
end

def visible?(_member, _context)
true
end
end
end
Expand Down
10 changes: 4 additions & 6 deletions lib/graphql/schema/visibility/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def initialize(context:, schema:, name: nil)
context[:visibility_migration_running] = true
warden_ctx_vals = context.to_h.dup
warden_ctx_vals[:visibility_migration_warden_running] = true
if defined?(schema::WardenCompatSchema)
warden_schema = schema::WardenCompatSchema
if schema.const_defined?(:WardenCompatSchema, false) # don't use a defn from a superclass
warden_schema = schema.const_get(:WardenCompatSchema, false)
else
warden_schema = Class.new(schema)
warden_schema.use_schema_visibility = false
Expand All @@ -98,10 +98,8 @@ def initialize(context:, schema:, name: nil)
schema.const_set(:WardenCompatSchema, warden_schema)
end
warden_ctx = GraphQL::Query::Context.new(query: context.query, values: warden_ctx_vals)
example_warden = GraphQL::Schema::Warden.new(schema: warden_schema, context: warden_ctx)
@warden_types = example_warden.schema_subset
warden_ctx.warden = example_warden
warden_ctx.types = @warden_types
warden_ctx.warden = GraphQL::Schema::Warden.new(schema: warden_schema, context: warden_ctx)
warden_ctx.types = @warden_types = warden_ctx.warden.schema_subset
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/schema/warden.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def visible_type?(type_defn, _ctx = nil); true; end
def visible_enum_value?(enum_value, _ctx = nil); true; end
def visible_type_membership?(type_membership, _ctx = nil); true; end
def interface_type_memberships(obj_type, _ctx = nil); obj_type.interface_type_memberships; end
def get_type(type_name); @schema.get_type(type_name); end # rubocop:disable Development/ContextIsPassedCop
def get_type(type_name); @schema.get_type(type_name, Query::NullContext.instance, false); end # rubocop:disable Development/ContextIsPassedCop
def arguments(argument_owner, ctx = nil); argument_owner.all_argument_definitions; end
def enum_values(enum_defn); enum_defn.enum_values; end # rubocop:disable Development/ContextIsPassedCop
def get_argument(parent_type, argument_name); parent_type.get_argument(argument_name); end # rubocop:disable Development/ContextIsPassedCop
Expand All @@ -100,7 +100,7 @@ def get_field(parent_type, field_name); @schema.get_field(parent_type, field_nam
def reachable_type?(type_name); true; end
def loadable?(type, _ctx); true; end
def reachable_types; @schema.types.values; end # rubocop:disable Development/ContextIsPassedCop
def possible_types(type_defn); @schema.possible_types(type_defn); end
def possible_types(type_defn); @schema.possible_types(type_defn, Query::NullContext.instance, false); end
def interfaces(obj_type); obj_type.interfaces; end
end

Expand Down

0 comments on commit 122272d

Please sign in to comment.