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? &&
^^^^^^^^^^^^^^^^^^^^
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:
Test:
Test output: