Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resources with circular relationships fail to load #453

Open
camsteffen opened this issue Jul 26, 2023 · 0 comments
Open

Resources with circular relationships fail to load #453

camsteffen opened this issue Jul 26, 2023 · 0 comments

Comments

@camsteffen
Copy link

Resources that form a cycle, especially where inheritance is involved, fail to load properly. Graphiti seems to always eagerly load related resource classes unlike ActiveRecord.

Implementation:

# person_resource.rb
class PersonResource < Graphiti::Resource
  self.abstract_class = true # this line is not necessary but changes the error
  has_one :company
end

# employee_resource.rb
class EmployeeResource < PersonResource
end

# company_resource.rb
class CompanyResource < Graphiti::Resource
  has_many :employees
end

Test:

require "rails_helper"

RSpec.describe "load EmployeeResource first" do
  it "works" do
    EmployeeResource
  end
end

Test output:

NoMethodError: undefined method `relationship_blocks' for nil:NilClass

        @serializer.relationship_blocks[sideload.name].nil? &&
                   ^^^^^^^^^^^^^^^^^^^^
@camsteffen camsteffen changed the title Resources with circular references fail to load Resources with circular relationships fail to load Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant