Skip to content

Load reqs with zeitwerk (drop ruby 2.3 support)#209

Merged
00dav00 merged 10 commits intomasterfrom
load_reqs_with_zeitwerk
Mar 5, 2022
Merged

Load reqs with zeitwerk (drop ruby 2.3 support)#209
00dav00 merged 10 commits intomasterfrom
load_reqs_with_zeitwerk

Conversation

@00dav00
Copy link
Copy Markdown
Contributor

@00dav00 00dav00 commented Jan 23, 2022

This PR uses (Zeitwerk)[https://github.com/fxn/zeitwerk] to loads the gem files.

Drops support for ruby 2.3

TODO

  • Add Zeitwerk to the gem dependencies
  • Configure Zeitwerk and change project structure to match it's requirements
  • Remove unnecessary require and require_relative calls
  • Create new concerns and deprecate old ones
  • Update generator to use new concerns

Copy link
Copy Markdown
Member

@mcelicalderon mcelicalderon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, @00dav00! My main concern is the versions we would need to drop support for. Ruby version and not sure if some versions of Rails. Ruby version might be fine at > 2.4.4, but not sure about rails if there's something around that

Comment thread graphql_devise.gemspec Outdated
spec.add_dependency 'devise_token_auth', '>= 0.1.43', '< 2.0'
spec.add_dependency 'graphql', '>= 1.8', '< 1.13.0'
spec.add_dependency 'rails', '>= 4.2', '< 6.2'
spec.add_dependency 'zeitwerk', '~> 2.2'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why ~> 2.2? Is it necessary to specify the version?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason, let me investigate a bit more about backwards compatibility in order to move this forward 👍

Comment thread lib/graphql_devise/routes_mounter.rb Outdated
module ActionDispatch::Routing
class Mapper
module GraphqlDevise
module RoutesMounter
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps RouteMounter. Or maybe GraphqlDevise::MountsRoute

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RouteMounter sounds good to me 👍

Comment thread lib/graphql_devise.rb Outdated

loader.setup

ActionDispatch::Routing::Mapper.send(:include, GraphqlDevise::RoutesMounter)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why send instead of

ActionDispatch::Routing::Mapper.include(GraphqlDevise::RoutesMounter)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread lib/graphql_devise.rb Outdated
require 'graphql'
require 'devise_token_auth'
require 'zeitwerk'
require_relative '../app/models/graphql_devise/concerns/model'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to explicitly require these, we should probably move them to lib so they are not autoloaded by the rails engine

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning to add new concerns that comply with Zeitwerk name constraints inside of lib and add deprecation warnings to the current constraints (for instance GraphqlDevise::Authenticable vs GraphqlDevise::Concerns::Model). Let me know if you still consider we should move them and I can address it in the next commits.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I think either way, we should probably move them away from the app directory as the engine will autoload that path too.

Comment thread lib/graphql_devise/engine.rb
@00dav00 00dav00 force-pushed the load_reqs_with_zeitwerk branch from 7c7c86a to 2abee77 Compare February 13, 2022 15:17
Copy link
Copy Markdown
Member

@mcelicalderon mcelicalderon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, @00dav00! Left some comments. Specially make sure we avoid code duplication on deprecated concerns. Also you are missing to do the same you did for the model concern for the controller concern (set_user_by_token). The legacy concerns should only include the new concern and show a deprecation warning. ControllerMethods is an internal concern, no need to deprecate that one, simply add the new one to the base mutation and resolver as you already did.

extend ActiveSupport::Concern

included do
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc, caller)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an internal concern, no need to deprecate. Simply use the new one in the base resolvers and mutations


included do
include DeviseTokenAuth::Concerns::User
include AdditionalModelMethods
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simply include the new concern and show deprecation warning on this one, no need to copy all the concern's code.

saved
else
raise(
GraphqlDevise::Error,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error is such a generic name that I think it doesn't harm to be explicit about which error

Comment thread spec/rails_helper.rb
@00dav00 00dav00 requested a review from mcelicalderon March 1, 2022 00:20
Copy link
Copy Markdown
Member

@mcelicalderon mcelicalderon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @00dav00 :shipit:

@00dav00 00dav00 merged commit 80db213 into master Mar 5, 2022
@00dav00 00dav00 deleted the load_reqs_with_zeitwerk branch March 5, 2022 23:04
@mcelicalderon mcelicalderon changed the title Load reqs with zeitwerk Load reqs with zeitwerk (drop ruby 2.3 support) Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants