Skip to content

Commit 9e9f4ca

Browse files
Alphabetize and cleanup
1 parent 7c02c83 commit 9e9f4ca

File tree

24 files changed

+58
-578
lines changed

24 files changed

+58
-578
lines changed

Gemfile

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,36 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
55

66
ruby '2.6.3'
77

8-
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
9-
gem 'rails', '~> 6.0.3', '>= 6.0.3.4'
10-
# Use postgresql as the database for Active Record
11-
gem 'pg', '>= 0.18', '< 2.0'
12-
# Use Puma as the app server
13-
gem 'puma', '~> 4.1'
14-
# Use SCSS for stylesheets
15-
gem 'sass-rails', '>= 6'
16-
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
17-
gem 'webpacker', '~> 4.0'
18-
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
19-
gem 'turbolinks', '~> 5'
20-
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
21-
gem 'jbuilder', '~> 2.7'
22-
# Use Redis adapter to run Action Cable in production
23-
# gem 'redis', '~> 4.0'
24-
# Use Active Model has_secure_password
258
gem 'bcrypt', '~> 3.1.7'
26-
27-
# Use Active Storage variant
28-
# gem 'image_processing', '~> 1.2'
29-
30-
# Reduces boot times through caching; required in config/boot.rb
319
gem 'bootsnap', '>= 1.4.2', require: false
32-
3310
gem 'graphql'
11+
gem 'jbuilder', '~> 2.7'
3412
gem 'jwt'
35-
36-
group :development, :test do
37-
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
38-
gem 'byebug', platforms: %i[mri mingw x64_mingw]
39-
end
13+
gem 'pg', '>= 0.18', '< 2.0'
14+
gem 'puma', '~> 4.1'
15+
gem 'rails', '~> 6.0.3', '>= 6.0.3.4'
16+
gem 'sass-rails', '>= 6'
17+
gem 'turbolinks', '~> 5'
18+
gem 'webpacker', '~> 4.0'
4019

4120
group :development do
42-
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
43-
gem 'listen', '~> 3.2'
44-
gem 'web-console', '>= 3.3.0'
45-
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
4621
gem 'graphiql-rails'
22+
gem 'listen', '~> 3.2'
4723
gem 'rubocop'
4824
gem 'rubocop-performance'
4925
gem 'rubocop-rails'
5026
gem 'rubocop-rspec'
5127
gem 'spring'
5228
gem 'spring-watcher-listen', '~> 2.0.0'
29+
gem 'web-console', '>= 3.3.0'
30+
end
31+
32+
group :development, :test do
33+
gem 'byebug', platforms: %i[mri mingw x64_mingw]
5334
end
5435

5536
group :test do
56-
# Adds support for Capybara system testing and selenium driver
5737
gem 'capybara', '>= 2.15'
5838
gem 'selenium-webdriver'
59-
# Easy installation and use of web drivers to run system tests with browsers
6039
gem 'webdrivers'
6140
end

app/controllers/graphql_controller.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ def current_user(token)
2828
JwtHelper.logged_in_user(token)
2929
end
3030

31-
# Handle variables in form data, JSON body, or a blank value
31+
def handle_error_in_development(e)
32+
logger.error(e.message)
33+
logger.error(e.backtrace.join("\n"))
34+
35+
render json: { errors: [{ message: e.message, backtrace: e.backtrace }], data: {} }, status: 500
36+
end
37+
3238
def prepare_variables(variables_param)
3339
case variables_param
3440
when String
@@ -40,19 +46,11 @@ def prepare_variables(variables_param)
4046
when Hash
4147
variables_param
4248
when ActionController::Parameters
43-
variables_param.to_unsafe_hash # GraphQL-Ruby will validate name and type of incoming variables.
49+
variables_param.to_unsafe_hash
4450
when nil
4551
{}
4652
else
4753
raise ArgumentError, "Unexpected parameter: #{variables_param}"
4854
end
4955
end
50-
51-
def handle_error_in_development(e)
52-
logger.error(e.message)
53-
logger.error(e.backtrace.join("\n"))
54-
55-
# render json: { errors: [{ message: e.message, backtrace: e.backtrace }], data: {} }, status: 500
56-
render json: { errors: [{ message: e.message }], data: {} }, status: 500
57-
end
5856
end

app/graph/authentication/mutations/login.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Authentication::Mutations
44
class Login < Base::Mutations::BaseMutation
55
argument :credentials, Authentication::Types::Input::AuthProviderCredentialsInput, required: false
6+
67
field :token, String, null: true
78
field :user, User::Types::UserType, null: true
89

app/graph/user/mutations/register.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ class AuthProviderSignupData < Base::Types::BaseInputObject
99
argument :auth_provider, AuthProviderSignupData, required: false
1010
argument :last_name, String, required: true
1111
argument :first_name, String, required: true
12+
1213
type User::Types::UserType
1314

1415
def resolve(first_name: nil, last_name: nil, auth_provider: nil)
1516
User.create!(
17+
email: auth_provider&.[](:credentials)&.[](:email),
1618
first_name: first_name,
1719
last_name: last_name,
18-
email: auth_provider&.[](:credentials)&.[](:email),
1920
password: auth_provider&.[](:credentials)&.[](:password)
2021
)
2122
rescue ActiveRecord::RecordInvalid => e

app/graph/user/mutations/update_user.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module User::Mutations
44
class UpdateUser < Base::Mutations::BaseMutation
55
argument :arguments, User::Types::Input::UpdateUser, required: true
6+
67
field :user, User::Types::UserType, null: true
78

89
def resolve(arguments:)

app/graph/user/queries/fetch_user.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
module User::Queries
44
class FetchUser < Base::Mutations::BaseMutation
55
argument :arguments, User::Types::Input::FetchUser, required: true
6+
67
field :user, User::Types::UserType, null: true
78

89
def resolve(arguments:)
910
current_user = context[:current_user]
1011
raise StandardError unless current_user
1112

1213
_type, item_id = RubyJwtPostgresAuthSchema.object_from_id(arguments[:id], nil)
13-
user = User.find(item_id)
14-
{ user: user }
14+
{ user: User.find(item_id) }
1515
rescue ActiveRecord::RecordNotFound => e
1616
GraphQL::ExecutionError.new("Invalid input: #{e.message}")
1717
rescue StandardError

config/application.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
# frozen_string_literal: true
22

33
require_relative 'boot'
4-
54
require 'rails/all'
65

7-
# Require the gems listed in Gemfile, including any gems
8-
# you've limited to :test, :development, or :production.
96
Bundler.require(*Rails.groups)
10-
117
module RubyJwtPostgresAuth
128
class Application < Rails::Application
139
config.api_only = true
14-
15-
# Initialize configuration defaults for originally generated Rails version.
1610
config.load_defaults(6.0)
1711

18-
# Settings in config/environments/* take precedence over those specified here.
19-
# Application configuration can go into files in config/initializers
20-
# -- all .rb files in that directory are automatically loaded after loading
21-
# the framework and any gems in your application.
22-
2312
config.before_configuration do
2413
env_file = File.join(Rails.root, 'config', 'local_env.yml')
2514
if File.exist?(env_file)

config/database.yml

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,13 @@
1-
# PostgreSQL. Versions 9.3 and up are supported.
2-
#
3-
# Install the pg driver:
4-
# gem install pg
5-
# On macOS with Homebrew:
6-
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7-
# On macOS with MacPorts:
8-
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
9-
# On Windows:
10-
# gem install pg
11-
# Choose the win32 build.
12-
# Install PostgreSQL and put its /bin directory on your path.
13-
#
14-
# Configure Using Gemfile
15-
# gem 'pg'
16-
#
171
default: &default
182
adapter: postgresql
193
encoding: unicode
20-
# For details on connection pooling, see Rails configuration guide
21-
# https://guides.rubyonrails.org/configuring.html#database-pooling
224
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
23-
245
development:
256
<<: *default
267
database: rjpa_development
27-
28-
# The specified database role being used to connect to postgres.
29-
# To create additional roles in postgres see `$ createuser --help`.
30-
# When left blank, postgres will use the default role. This is
31-
# the same name as the operating system user that initialized the database.
32-
#username: ruby_jwt_postgres_auth
33-
34-
# The password associated with the postgres role (username).
35-
#password:
36-
37-
# Connect on a TCP socket. Omitted by default since the client uses a
38-
# domain socket that doesn't need configuration. Windows does not have
39-
# domain sockets, so uncomment these lines.
40-
#host: localhost
41-
42-
# The TCP port the server listens on. Defaults to 5432.
43-
# If your server runs on a different port number, change accordingly.
44-
#port: 5432
45-
46-
# Schema search path. The server defaults to $user,public
47-
#schema_search_path: myapp,sharedapp,public
48-
49-
# Minimum log levels, in increasing order:
50-
# debug5, debug4, debug3, debug2, debug1,
51-
# log, notice, warning, error, fatal, and panic
52-
# Defaults to warning.
53-
#min_messages: notice
54-
55-
# Warning: The database defined as "test" will be erased and
56-
# re-generated from your development database when you run "rake".
57-
# Do not set this db to the same as development or production.
588
test:
599
<<: *default
6010
database: rjpa_test
61-
62-
# As with config/credentials.yml, you never want to store sensitive information,
63-
# like your database password, in your source code. If your source code is
64-
# ever seen by anyone, they now have access to your database.
65-
#
66-
# Instead, provide the password as a unix environment variable when you boot
67-
# the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
68-
# for a full rundown on how to provide these environment variables in a
69-
# production deployment.
70-
#
71-
# On Heroku and other platform providers, you may have a full connection URL
72-
# available as an environment variable. For example:
73-
#
74-
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
75-
#
76-
# You can use this database configuration with:
77-
#
78-
# production:
79-
# url: <%= ENV['DATABASE_URL'] %>
80-
#
8111
production:
8212
<<: *default
8313
database: rjpa_production

config/environment.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
# Load the Rails application.
43
require_relative 'application'
54

6-
# Initialize the Rails application.
75
Rails.application.initialize!

config/environments/development.rb

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,29 @@
11
# frozen_string_literal: true
22

33
Rails.application.configure do
4-
# Settings specified here will take precedence over those in config/application.rb.
5-
6-
# In the development environment your application's code is reloaded on
7-
# every request. This slows down response time but is perfect for development
8-
# since you don't have to restart the web server when you make code changes.
94
config.cache_classes = false
10-
11-
# Do not eager load code on boot.
12-
config.eager_load = false
13-
14-
# Show full error reports.
155
config.consider_all_requests_local = true
6+
config.eager_load = false
167

17-
# Enable/disable caching. By default caching is disabled.
18-
# Run rails dev:cache to toggle caching.
198
if Rails.root.join('tmp', 'caching-dev.txt').exist?
20-
config.action_controller.perform_caching = true
219
config.action_controller.enable_fragment_cache_logging = true
22-
10+
config.action_controller.perform_caching = true
2311
config.cache_store = :memory_store
2412
config.public_file_server.headers = {
2513
"Cache-Control": "public, max-age=#{Integer(2.days, 10)}"
2614
}
2715
else
2816
config.action_controller.perform_caching = false
29-
3017
config.cache_store = :null_store
3118
end
3219

33-
# Store uploaded files on the local file system (see config/storage.yml for options).
34-
config.active_storage.service = :local
35-
36-
# Don't care if the mailer can't send.
37-
config.action_mailer.raise_delivery_errors = false
38-
3920
config.action_mailer.perform_caching = false
40-
41-
# Print deprecation notices to the Rails logger.
42-
config.active_support.deprecation = :log
43-
44-
# Raise an error on page load if there are pending migrations.
21+
config.action_mailer.raise_delivery_errors = false
4522
config.active_record.migration_error = :page_load
46-
47-
# Highlight code that triggered database queries in logs.
4823
config.active_record.verbose_query_logs = true
49-
50-
# Debug mode disables concatenation and preprocessing of assets.
51-
# This option may cause significant delays in view rendering with a large
52-
# number of complex assets.
24+
config.active_storage.service = :local
25+
config.active_support.deprecation = :log
5326
config.assets.debug = true
54-
55-
# Suppress logger output for asset requests.
5627
config.assets.quiet = true
57-
58-
# Raises error for missing translations.
59-
# config.action_view.raise_on_missing_translations = true
60-
61-
# Use an evented file watcher to asynchronously detect changes in source code,
62-
# routes, locales, etc. This feature depends on the listen gem.
6328
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
6429
end

0 commit comments

Comments
 (0)