forked from zauberware/rails-devise-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
21 changed files
with
288 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mutations | ||
# Base mutation class for app | ||
class BaseMutation < GraphQL::Schema::Mutation | ||
def current_ability | ||
Ability.new(context[:current_user]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mutations | ||
module Companies | ||
# Updates an existing company. | ||
class UpdateCompany < Mutations::BaseMutation | ||
description 'Updates an existing company.' | ||
argument :id, ID, required: true | ||
argument :attributes, Types::Companies::CompanyInputType, required: true | ||
payload_type Types::Companies::CompanyType | ||
|
||
def resolve(id:, attributes:) | ||
# find company | ||
company = ::Companies::Company.accessible_by(current_ability).find_by(id: id) | ||
if company.nil? | ||
raise I18n.t('errors.messages.resource_not_found', resource: ::Companies::Company.model_name.human) | ||
end | ||
|
||
company.attributes = attributes.to_h | ||
current_ability.authorize! :update, company | ||
return company if company.save! | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resolvers | ||
module Companies | ||
# Resolver to return a user | ||
class Company < ::Resolvers::BaseResolver | ||
type Types::Companies::CompanyType, null: true | ||
description 'Returns the company for the user.' | ||
|
||
def resolve | ||
context[:current_user] ? context[:current_user].company : nil | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module Types | ||
module Companies | ||
# Attributes to update a company. | ||
class CompanyInputType < Types::BaseInputObject | ||
description 'Attributes to update a company.' | ||
argument :name, String, 'Name of company', required: true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
module Types | ||
module Companies | ||
# GraphQL type for a company | ||
class CompanyType < ::Types::BaseModel | ||
field :name, String, null: false | ||
field :slug, String, null: true | ||
# field :users, [::Types::UserType], null: true | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# frozen_string_literal: true | ||
|
||
module Companies | ||
# == Schema Information | ||
# | ||
# Table name: companies | ||
# | ||
# id :uuid not null, primary key | ||
# name :string | ||
# slug :string | ||
# users_count :integer | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
# Indexes | ||
# | ||
# index_companies_on_slug (slug) UNIQUE | ||
# | ||
class Company < ApplicationRecord | ||
extend FriendlyId | ||
|
||
self.table_name = 'companies' | ||
|
||
# - EXTENSIONS | ||
friendly_id :name, use: :slugged | ||
|
||
# - VALIDATIONS | ||
validates :name, presence: true | ||
validates :name, length: { maximum: 255 } | ||
validates :slug, length: { maximum: 255 } | ||
|
||
# - RELATIONS | ||
has_many :users, dependent: :destroy | ||
|
||
# override friendly id checker for categories | ||
def should_generate_new_friendly_id? | ||
(slug.nil? || slug.blank?) || (name_changed? && !slug_changed?) | ||
end | ||
|
||
# :nocov: | ||
rails_admin do | ||
weight 10 | ||
navigation_icon 'fa fa-building' | ||
|
||
list do | ||
field :id | ||
field :name | ||
field :slug | ||
field :users_count | ||
end | ||
|
||
edit do | ||
field :name | ||
field :slug | ||
end | ||
|
||
show do | ||
field :id | ||
field :name | ||
field :slug | ||
field :users_count | ||
end | ||
end | ||
|
||
# :nocov: | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.