Skip to content

Commit 8a9d730

Browse files
committed
clean up files after rubocop linting
1 parent 596baa4 commit 8a9d730

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+496
-339
lines changed

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Add your own tasks in files placed in lib/tasks ending in .rake,
24
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
35

app/channels/application_cable/channel.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ApplicationCable
24
class Channel < ActionCable::Channel::Base
35
end

app/channels/application_cable/connection.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ApplicationCable
24
class Connection < ActionCable::Connection::Base
35
end
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
2+
13
class ApplicationController < ActionController::API
2-
34
end

app/controllers/graphql_controller.rb

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,65 @@
1+
# frozen_string_literal: true
2+
3+
# GraphQL API entry point
14
class GraphqlController < ApplicationController
5+
# Executes the graphql request
6+
def execute
7+
query, variables, operation_name = read_query_params()
8+
context = set_context()
9+
result = GraphqlSchema.execute(
10+
query,
11+
variables: variables,
12+
context: context,
13+
operation_name: operation_name
14+
)
15+
render json: result
16+
rescue StandardError => e
17+
raise e unless Rails.env.development?
218

3-
def execute
4-
variables = ensure_hash(params[:variables])
5-
query = params[:query]
6-
operation_name = params[:operationName]
7-
context = {
8-
current_user: current_user,
9-
login: method(:sign_in)
10-
}
11-
result = GraphqlSchema.execute(
12-
query,
13-
variables: variables,
14-
context: context,
15-
operation_name: operation_name
16-
)
17-
render json: result
18-
rescue => e
19-
raise e unless Rails.env.development?
20-
handle_error_in_development e
21-
end
22-
23-
private
24-
# Handle form data, JSON body, or a blank value
25-
def ensure_hash(ambiguous_param)
26-
case ambiguous_param
27-
when String
28-
if ambiguous_param.present?
29-
ensure_hash(JSON.parse(ambiguous_param))
30-
else
31-
{}
32-
end
33-
when Hash, ActionController::Parameters
34-
ambiguous_param
35-
when nil
36-
{}
37-
else
38-
raise ArgumentError, "Unexpected parameter: #{ambiguous_param}"
39-
end
40-
end
41-
42-
def handle_error_in_development(e)
43-
logger.error e.message
44-
logger.error e.backtrace.join("\n")
45-
46-
render json: {
47-
error: {
48-
message: e.message,
49-
backtrace: e.backtrace
50-
},
51-
data: {}
52-
}, status: 500
19+
handle_error_in_development e
20+
end
21+
22+
private
23+
24+
def read_query_params
25+
[
26+
params[:query],
27+
ensure_hash(params[:variables]),
28+
params[:operationName]
29+
]
30+
end
31+
32+
def set_context
33+
{
34+
current_user: current_user
35+
# login: method(:sign_in)
36+
}
37+
end
38+
39+
# Handle form data, JSON body, or a blank value
40+
def ensure_hash(ambiguous_param)
41+
case ambiguous_param
42+
when String
43+
ambiguous_param.present? ? ensure_hash(JSON.parse(ambiguous_param)) : {}
44+
when Hash, ActionController::Parameters
45+
ambiguous_param
46+
when nil
47+
{}
48+
else
49+
raise ArgumentError, "Unexpected parameter: #{ambiguous_param}"
5350
end
5451
end
55-
52+
53+
def handle_error_in_development(err)
54+
logger.error err.message
55+
logger.error err.backtrace.join("\n")
56+
57+
render json: {
58+
error: {
59+
message: err.message,
60+
backtrace: err.backtrace
61+
},
62+
data: {}
63+
}, status: 500
64+
end
65+
end

app/graphql/graphql_schema.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
# Entry point for graphql schema
14
class GraphqlSchema < GraphQL::Schema
2-
query(Types::QueryType)
3-
mutation(Types::MutationType)
4-
end
5-
5+
query(Types::QueryType)
6+
mutation(Types::MutationType)
7+
end

app/graphql/mutations/user/login.rb

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
class Mutations::User::Login < GraphQL::Schema::Mutation
1+
# frozen_string_literal: true
22

3-
null true
4-
description "Login for users"
5-
argument :email, String, required: true
6-
argument :password, String, required: true
7-
payload_type Types::UserType
3+
module Mutations
4+
module User
5+
# Login for users
6+
class Login < GraphQL::Schema::Mutation
7+
null true
8+
description 'Login for users'
9+
argument :email, String, required: true
10+
argument :password, String, required: true
11+
payload_type Types::UserType
812

9-
def resolve(email:, password:)
10-
user = User.find_for_authentication(email: email)
11-
return nil if !user
12-
13-
is_valid_for_auth = user.valid_for_authentication?{
14-
user.valid_password?(password)
15-
}
16-
return is_valid_for_auth ? user : nil
17-
end
13+
def resolve(email:, password:)
14+
user = ::User.find_for_authentication(email: email)
15+
return nil unless user
1816

19-
end
17+
is_valid_for_auth = user.valid_for_authentication? do
18+
user.valid_password?(password)
19+
end
20+
is_valid_for_auth ? user : nil
21+
end
22+
end
23+
end
24+
end

app/graphql/mutations/user/logout.rb

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
class Mutations::User::Logout < GraphQL::Schema::Mutation
1+
# frozen_string_literal: true
22

3-
null true
4-
description "Logout for users"
5-
payload_type Boolean
3+
module Mutations
4+
module User
5+
# Logout for users
6+
class Logout < GraphQL::Schema::Mutation
7+
null true
8+
description 'Logout for users'
9+
payload_type Boolean
610

7-
def resolve
8-
if context[:current_user]
9-
context[:current_user].update(jti: SecureRandom.uuid)
10-
return true
11-
end
12-
false
11+
def resolve
12+
user = context[:current_user]
13+
if user
14+
user.update(jti: SecureRandom.uuid)
15+
return true
16+
end
17+
false
18+
end
19+
end
1320
end
14-
15-
end
21+
end
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
class Mutations::User::ResendUnlockInstructions < GraphQL::Schema::Mutation
1+
# frozen_string_literal: true
22

3-
null false
4-
description "Unlock the user account"
5-
argument :email, String, required: true
6-
payload_type Boolean
3+
module Mutations
4+
module User
5+
# Unlock the user account
6+
class ResendUnlockInstructions < GraphQL::Schema::Mutation
7+
null false
8+
description 'Unlock the user account'
9+
argument :email, String, required: true
10+
payload_type Boolean
711

8-
def resend_unlock_instructions(email:)
9-
user = User.find_by_email(email)
10-
return false if !user
11-
user.resend_unlock_instructions
12-
end
12+
def resend_unlock_instructions(email:)
13+
user = ::User.find_by(email: email)
14+
return false unless user
1315

14-
end
16+
user.resend_unlock_instructions
17+
end
18+
end
19+
end
20+
end
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
class Mutations::User::ResetPassword < GraphQL::Schema::Mutation
1+
# frozen_string_literal: true
22

3-
null true
4-
description "Set the new password"
5-
argument :password, String, required: true
6-
argument :passwordConfirmation, String, required: true
7-
argument :resetPasswordToken, String, required: true
8-
payload_type Boolean
3+
module Mutations
4+
module User
5+
# Set the new password
6+
class ResetPassword < GraphQL::Schema::Mutation
7+
null true
8+
description 'Set the new password'
9+
argument :password, String, required: true
10+
argument :passwordConfirmation, String, required: true
11+
argument :resetPasswordToken, String, required: true
12+
payload_type Boolean
913

10-
def resolve(password:, password_confirmation:, reset_password_token:)
11-
user = User.with_reset_password_token(reset_password_token)
12-
return false if !user
13-
user.reset_password(password, password_confirmation)
14-
end
14+
def resolve(password:, password_confirmation:, reset_password_token:)
15+
user = ::User.with_reset_password_token(reset_password_token)
16+
return false unless user
1517

16-
end
18+
user.reset_password(password, password_confirmation)
19+
end
20+
end
21+
end
22+
end

0 commit comments

Comments
 (0)