Skip to content

Refactor routes mount method#67

Merged
mcelicalderon merged 5 commits intomasterfrom
refactor_routes
Mar 21, 2020
Merged

Refactor routes mount method#67
mcelicalderon merged 5 commits intomasterfrom
refactor_routes

Conversation

@00dav00
Copy link
Copy Markdown
Contributor

@00dav00 00dav00 commented Feb 8, 2020

Refactor routes addition with sanitizer class

  • Add operation sanititzer class
  • Add operation preparer class
  • Refactor routes creation with utilitary classes

def call
result = {}

@mutations.each do |action, mutation|
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.

@mutations.each_with_object({}) do |(action, mutation), result|
  ...
  result[mapped_action] = new_mutation
end

def call
result = {}

@queries.each do |action, query|
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.

each_with_object can also be used here

GraphqlDevise::Types::QueryType.field(action, resolver: resolver)
end

if (used_queries.blank? || additional_queries.present?) && GraphqlDevise::Types::QueryType.fields.blank?
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.

I think the names are better if you are more explicit about what the variable holds

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.

I don't think we should change file structure and not take advantage of autoload by using rails engine dir structure.

Comment thread lib/graphql_devise/rails/routes.rb Outdated
resource.pluralize.underscore.tr('/', '_').to_sym,
module: :devise,
skip: [:sessions, :registrations, :passwords, :confirmations, :omniauth_callbacks, :unlocks, :invitations]
skip: [DEVISE_OPERATIONS]
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.

Constant already an array

end

def call
result = @default
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.

No need for this assignment if line 21 has no conditional assignment

Comment thread lib/graphql_devise/rails/routes.rb Outdated

path = opts.fetch(:at, '/graphql_auth')
mapping_name = resource.underscore.tr('/', '_').to_sym
validate_gql_devise_operations!(param_operations)
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.

Still think you should call the new class method here directly instead of adding another method to rails router

Comment thread lib/graphql_devise/rails/routes.rb Outdated
end
additional_queries.each do |action, resolver|

# if all_mutations.present? && GraphqlDevise::Schema.try(:mutation).nil?
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.

I don't think try should replace the version check. I think all versions respond to the method actually. Plus the mutation method behaves differently on gql 1.10

Comment thread spec/requests/mutations/login_spec.rb Outdated
end

before { post_request }
before { post_request('/api/v1/guest/graphql_auth') }
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.

Is this necessary?

end

it 'works without the confirmable module' do
expect { post_request }.to change(Guest, :count).from(0).to(1)
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.

I don't think by is an improvement over the explicit start and end count you expect

Comment thread spec/operation_sanitizer_spec.rb Outdated
describe '.call' do
subject { described_class.call(default: default, custom: custom, only: only, skipped: skipped) }

let(:op_class_1) { Class.new }
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.

numbers in variables

Comment thread spec/operation_sanitizer_spec.rb Outdated
context 'when there are custom operations' do
let(:custom) { { operation_1: op_class_3, bad_operation: GraphQL::Schema::Resolver } }

it { is_expected.to eq(operation_1: op_class_3, operation_2: op_class_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.

all numbers in variables, we should add the rule to rubocop


if (used_mutations.present? || additional_mutations.present?) &&
(Gem::Version.new(GraphQL::VERSION) <= Gem::Version.new('1.10.0') || GraphqlDevise::Schema.mutation.nil?)
GraphqlDevise::Schema.mutation(GraphqlDevise::Types::MutationType)
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.

There was a reason for this not no be added if the mutation type has no mutations. You will get an error when making a request saying that the mutation type needs at least one field

David Revelo added 3 commits March 15, 2020 09:45
Add operation sanitizer class
Refactor sanitizer to have single responsability
Add operations checker class
Add mutations and queries preparer
Load default types, mutations and resolvers explicitely
Use try instead of gem version to check for mutation type
@00dav00 00dav00 force-pushed the refactor_routes branch 3 times, most recently from 0d298f4 to 927858c Compare March 15, 2020 14:54
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.

New test case doesn't really test the schema having absolutely no mutations

@00dav00 00dav00 force-pushed the refactor_routes branch 3 times, most recently from e9f7f67 to 144d07b Compare March 21, 2020 13:10
@mcelicalderon mcelicalderon changed the title Add operation sanitizer class Refactor routes mount method Mar 21, 2020
@mcelicalderon mcelicalderon merged commit e466279 into master Mar 21, 2020
@mcelicalderon mcelicalderon deleted the refactor_routes branch March 21, 2020 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants