Skip to content

Resources with circular relationships fail to load #453

Closed

Description

@camsteffen

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? &&
                   ^^^^^^^^^^^^^^^^^^^^

Activity

  1. changed the title [-]Resources with circular references fail to load[/-] [+]Resources with circular relationships fail to load[/+] on Aug 15, 2023
  2. added theissue type on Mar 18, 2025
  3. jkeen commented on Jul 29, 2026

    @jkeen
    Collaborator

    #492 made relation resources lazily constantized, which should resolve the circular-load failure. Can you confirm this still exists in the current version?

  4. camsteffen commented on Jul 29, 2026

    @camsteffen
    Author

    Sorry, I'm no longer involved with a project using graphiti. I believe my original example should be a sufficient test.

  5. added a commit that references this issue on Aug 24, 2026
    6036392
  6. added a commit that references this issue on Sep 1, 2026
  7. github-actions commented on Sep 1, 2026

    @github-actions
    Contributor

    🎉 This issue has been resolved in version 2.0.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions