graphiti-api / graphiti

Stylish Graph APIs
https://www.graphiti.dev/
MIT License
960 stars 138 forks source link

Not compatible with Rails 7.1 #460

Closed svobom57 closed 4 months ago

svobom57 commented 5 months ago

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.

aravindaytha12 commented 3 months ago

Hi @svobom57 , @richmolj,

(1) This file changes not reflected after doing bundle install in my project and in gems path gem 'graphiti'

(2) To get this change for my project I have used along with branch gem 'graphiti', git: "https://github.com/graphiti-api/graphiti.git", branch: 'master'

(3) May I know what is the default branch while we use in Gemfile and Why this change not reflected

If this PR is closed, can please merge this master branch changes into the required branch So, that without any branches I can direct use in my project path as gem 'graphiti'

jkeen commented 3 months ago

@aravindaytha12 1.4.0 was just officially released, so option 1 should load that version which contains the fixes you need

aravindaytha12 commented 3 months ago

@aravindaytha12 1.4.0 was just officially released, so option 1 should load that version which contains the fixes you need

Thanks @jkeen ..!