Skip to content

[GraphQL::Schema::Visibility] Inherited schemas don't preload resulting in crash #5384

@cocoahero

Description

@cocoahero

TL;DR;

When a parent schema enables the GraphQL::Schema::Visibility plugin using preload: true, child schemas will crash when declaring the root query object.

/ruby/3.4.4/gems/graphql-2.5.9/lib/graphql/schema/visibility.rb:191:in 'GraphQL::Schema::Visibility#ensure_all_loaded': undefined method 'add?' for nil (NoMethodError)

    if type.kind.fields? && @preloaded_types.add?(type)
                                            ^^^^^
from /ruby/3.4.4/gems/graphql-2.5.9/lib/graphql/schema/visibility.rb:96:in 'GraphQL::Schema::Visibility#query_configured'
from /ruby/3.4.4/gems/graphql-2.5.9/lib/graphql/schema.rb:451:in 'GraphQL::Schema.query'
from ./example.rb:20:in '<class:ConcreteSchema>'
from ./example.rb:19:in '<main>'

I believe the issue is here, where the visibility instance is duplicated with preload: true, but the preloaded state is not initialized / copied.

Version

/ruby/3.4.4/gems/graphql-2.5.9

Example

class QueryRoot < GraphQL::Schema::Object
  field :hello, String, null: false

  def hello
    "Hello, world!"
  end
end

class AbstractSchema < GraphQL::Schema
  # simulate Rails.env.production? == true
  use(GraphQL::Schema::Visibility, preload: true)
end

class ConcreteSchema < AbstractSchema
  query(QueryRoot)
end

result = ConcreteSchema.execute("{ hello }")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions