graphiti
graphiti copied to clipboard
Not compatible with Rails 7.1
Description
We recently tried migrating our app to Rails 7.1 and hit a road block with Graphiti. When I now try to spin up my Rails environment (with eager_load = true
) I get errors similar to this:
vendor/bundle/ruby/3.2.0/gems/graphiti-1.3.9/lib/graphiti/util/serializer_relationships.rb:122:in
`validate_link_for_sideload!': UserResource: Cannot link to sideload :listings! (Graphiti::Errors::InvalidLink)
Make sure the endpoint "/api/selling/listings" exists with action :index, or customize the endpoint for Selling::ListingResource.
If you do not wish to generate a link, pass link: false or set self.autolink = false.
I managed to debug what the issue is:
This issue is due to this line of code in Graphiti:
https://github.com/graphiti-api/graphiti/blob/14e84ef7e10c347ec391b96948365b5195074632/lib/graphiti/util/serializer_relationships.rb#L121
that now returns nil
after Rails 7.1 upgrade. The Graphiti.config.context_for_endpoint
is initialized here:
https://github.com/graphiti-api/graphiti/blob/14e84ef7e10c347ec391b96948365b5195074632/lib/graphiti/railtie.rb#L113
So it seems like the above call is now not returning the route properly when a symbol
route is passed into it anymore.
If I cast the sideload.resource.endpoint[:full_path]
to a string it starts working again...
This is because:
::Rails.application.routes.recognize_path(:"/api/selling/listings", method: :get)
NoMethodError: undefined method `include?' for :"/api/selling/listings":Symbol
from /usr/local/bundle/gems/actionpack-7.1.1/lib/action_dispatch/routing/route_set.rb:887:in `recognize_path'
since the implementation of the Rails.application.routes.recognize_path
changed in Rails 7.1.