Skip to content

Commit

Permalink
should be good for a first pass
Browse files Browse the repository at this point in the history
  • Loading branch information
fermion committed Jan 5, 2024
1 parent d0b3d77 commit eb5caa6
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/controllers/graphql_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def execute
context = {
# Query context goes here, for example:
current_user: current_user,
current_company: current_company
}
result = StaffplanReduxSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
render json: result
Expand Down
7 changes: 2 additions & 5 deletions app/graphql/mutations/base_mutation.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# frozen_string_literal: true

module Mutations
class BaseMutation < GraphQL::Schema::RelayClassicMutation
argument_class Types::BaseArgument
field_class Types::BaseField
input_object_class Types::BaseInputObject
object_class Types::BaseObject
class BaseMutation < GraphQL::Schema::Mutation
null false
end
end
14 changes: 14 additions & 0 deletions app/graphql/mutations/create_work_week.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Mutations
class CreateWorkWeek < BaseMutation
# arguments passed to the `resolve` method
# argument :description, String, required: true
# argument :url, String, required: true

# return type from the mutation
type Types::StaffPlan::WorkWeekType

def resolve
# TODO: implement
end
end
end
13 changes: 13 additions & 0 deletions app/graphql/mutations/set_current_company.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Mutations
class SetCurrentCompany < BaseMutation
# arguments passed to the `resolve` method
argument :company_id, ID, required: true

# return type from the mutation
type Types::StaffPlan::CompanyType

def resolve
# TODO: implement
end
end
end
14 changes: 14 additions & 0 deletions app/graphql/mutations/update_work_week.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Mutations
class UpdateWorkWeek < BaseMutation
# arguments passed to the `resolve` method
# argument :description, String, required: true
# argument :url, String, required: true

# return type from the mutation
type Types::StaffPlan::WorkWeekType

def resolve
# TODO: implement
end
end
end
9 changes: 3 additions & 6 deletions app/graphql/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

module Types
class MutationType < Types::BaseObject
# TODO: remove me
field :test_field, String, null: false,
description: "An example field added by the generator"
def test_field
"Hello World"
end
field :set_current_company, mutation: Mutations::SetCurrentCompany
field :create_work_week, mutation: Mutations::CreateWorkWeek
field :update_work_week, mutation: Mutations::UpdateWorkWeek
end
end
27 changes: 24 additions & 3 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,30 @@ def clients
context[:current_user].current_company.clients.all
end

field :assignments, [Types::StaffPlan::AssignmentType], null: false
def assignments
context[:current_user].assignments.all
field :project_assignments, [Types::StaffPlan::AssignmentType], null: false do
argument :project_id, ID, required: true, description: "ID of the project to fetch assignments for."
end

def project_assignments(project_id: nil)
context[:current_company]
.projects
.find(project_id)
.assignments
.all
end

field :user_assignments, [Types::StaffPlan::AssignmentType], null: false do
argument :user_id, ID, required: false,
description: "ID of the user to fetch assignments for. The current user's assignments will be returned if this argument is not provided."
end
def user_assignments(user_id: nil)
target = if user_id.present?
context[:current_company].users.find(user_id)
else
context[:current_user]
end

target.assignments.all
end

field :users, [Types::StaffPlan::UserType], null: false
Expand Down
4 changes: 2 additions & 2 deletions app/graphql/types/staff_plan/assignment_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module Types
module StaffPlan
class AssignmentType < Types::BaseObject
field :id, ID, null: false
field :user_id, ID, null: false
field :project_id, ID, null: false
field :user, Types::StaffPlan::UserType, null: false
field :project, Types::StaffPlan::ProjectType, null: false
field :status, String, null: false
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/staff_plan/project_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Types
module StaffPlan
class ProjectType < Types::BaseObject
field :id, ID, null: false
field :client_id, ID, null: false
field :client, Types::StaffPlan::ClientType, null: false
field :name, String, null: false
field :status, String, null: false
field :payment_frequency, String, null: false
Expand Down
3 changes: 1 addition & 2 deletions app/graphql/types/staff_plan/work_week_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Types
module StaffPlan
class WorkWeekType < Types::BaseObject
field :id, ID, null: false
field :user, Types::StaffPlan::UserType, null: false
field :assignment_id, Integer, null: false
field :cweek, Integer, null: false
field :year, Integer, null: false
Expand All @@ -13,8 +14,6 @@ class WorkWeekType < Types::BaseObject
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false

field :user, Types::StaffPlan::UserType, null: false

def user
object.user
end
Expand Down

0 comments on commit eb5caa6

Please sign in to comment.