Refactor routes mount method#67
Conversation
| def call | ||
| result = {} | ||
|
|
||
| @mutations.each do |action, mutation| |
There was a problem hiding this comment.
@mutations.each_with_object({}) do |(action, mutation), result|
...
result[mapped_action] = new_mutation
end| def call | ||
| result = {} | ||
|
|
||
| @queries.each do |action, query| |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
I think the names are better if you are more explicit about what the variable holds
mcelicalderon
left a comment
There was a problem hiding this comment.
I don't think we should change file structure and not take advantage of autoload by using rails engine dir structure.
| resource.pluralize.underscore.tr('/', '_').to_sym, | ||
| module: :devise, | ||
| skip: [:sessions, :registrations, :passwords, :confirmations, :omniauth_callbacks, :unlocks, :invitations] | ||
| skip: [DEVISE_OPERATIONS] |
| end | ||
|
|
||
| def call | ||
| result = @default |
There was a problem hiding this comment.
No need for this assignment if line 21 has no conditional assignment
|
|
||
| path = opts.fetch(:at, '/graphql_auth') | ||
| mapping_name = resource.underscore.tr('/', '_').to_sym | ||
| validate_gql_devise_operations!(param_operations) |
There was a problem hiding this comment.
Still think you should call the new class method here directly instead of adding another method to rails router
| end | ||
| additional_queries.each do |action, resolver| | ||
|
|
||
| # if all_mutations.present? && GraphqlDevise::Schema.try(:mutation).nil? |
There was a problem hiding this comment.
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
0dd8007 to
f5d5882
Compare
| end | ||
|
|
||
| before { post_request } | ||
| before { post_request('/api/v1/guest/graphql_auth') } |
| end | ||
|
|
||
| it 'works without the confirmable module' do | ||
| expect { post_request }.to change(Guest, :count).from(0).to(1) |
There was a problem hiding this comment.
I don't think by is an improvement over the explicit start and end count you expect
| describe '.call' do | ||
| subject { described_class.call(default: default, custom: custom, only: only, skipped: skipped) } | ||
|
|
||
| let(:op_class_1) { Class.new } |
| 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) } |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
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
0d298f4 to
927858c
Compare
mcelicalderon
left a comment
There was a problem hiding this comment.
New test case doesn't really test the schema having absolutely no mutations
e9f7f67 to
144d07b
Compare
3dc245e to
c08f7d2
Compare
1a5eeb6 to
b73d3ca
Compare
Refactor routes addition with sanitizer class