Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ gem "bootsnap", require: false

gem "graphql"

gem 'bcrypt'

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ GEM
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
bcrypt (3.1.18)
bindex (0.8.1)
bootsnap (1.16.0)
msgpack (~> 1.2)
Expand Down Expand Up @@ -213,6 +214,7 @@ PLATFORMS
x86_64-darwin-21

DEPENDENCIES
bcrypt
bootsnap
byebug
debug
Expand Down
20 changes: 20 additions & 0 deletions app/graphql/mutations/create_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Mutations
class CreateUser < BaseMutation
class AuthProviderSignupData < Types::BaseInputObject
argument :credentials, Types::AuthProviderCredentialsInput, required: false
end

argument :name, String, required: true
argument :auth_provider, AuthProviderSignupData, required: false

type Types::UserType

def resolve(name: nil, auth_provider: nil)
User.create!(
name: name,
email: auth_provider&.[](:credentials)&.[](:email),
password: auth_provider&.[](:credentials)&.[](:password)
)
end
end
end
8 changes: 8 additions & 0 deletions app/graphql/types/auth_provider_credentials_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Types
class AuthProviderCredentialsInput < BaseInputObject
graphql_name 'AUTH_PROVIDER_CREDENTIALS'

argument :email, String, required: true
argument :password, String, required: true
end
end
1 change: 1 addition & 0 deletions app/graphql/types/mutation_type.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Types
class MutationType < Types::BaseObject
field :create_user, mutation: Mutations::CreateUser
field :create_link, mutation: Mutations::CreateLink
end
end
9 changes: 9 additions & 0 deletions app/graphql/types/user_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Types
class UserType < Types::BaseObject
field :id, ID, null: false
field :name, String, null: false
field :email, String, null: false
end
end
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class User < ApplicationRecord
has_secure_password

validates :name, presence: true
validates :email, presence: true, uniqueness: true
end
11 changes: 11 additions & 0 deletions db/migrate/20230430114757_create_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :password_digest

t.timestamps
end
end
end
10 changes: 9 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryBot.define do
factory :user do
name { "MyString" }
email { "MyString" }
password_digest { "MyString" }
end
end
5 changes: 5 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe User, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end