Skip to content

Commit

Permalink
Removing fields from GraphQL that are not being used anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
caiosba committed Dec 3, 2023
1 parent a0db4a1 commit dc06b3b
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 307 deletions.
22 changes: 1 addition & 21 deletions app/graph/mutations/team_user_mutations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,8 @@ module TeamUserMutations
MUTATION_TARGET = 'team_user'.freeze
PARENTS = ['user','team'].freeze

module SharedCreateAndUpdateFields
extend ActiveSupport::Concern

included do
argument :role, GraphQL::Types::String, required: false
end
end

class Create < Mutations::CreateMutation
include SharedCreateAndUpdateFields

argument :user_id, GraphQL::Types::Int, required: true, camelize: false
argument :team_id, GraphQL::Types::Int, required: true, camelize: false
argument :status, GraphQL::Types::String, required: true
end

class Update < Mutations::UpdateMutation
include SharedCreateAndUpdateFields

argument :user_id, GraphQL::Types::Int, required: false, camelize: false
argument :team_id, GraphQL::Types::Int, required: false, camelize: false
argument :status, GraphQL::Types::String, required: false
argument :role, GraphQL::Types::String, required: false
end

class Destroy < Mutations::DestroyMutation; end
Expand Down
3 changes: 2 additions & 1 deletion app/graph/mutations/user_invitation_mutation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class UserInvitationMutation < Mutations::BaseMutation
field :team, TeamType, null: true

def resolve(invitation: nil, members:)
team = Team.find_if_can(Team.current.id, context[:ability])
messages = User.send_user_invitation(members, invitation)
{ errors: messages, team: Team.current }
{ errors: messages, team: team }
end
end
1 change: 0 additions & 1 deletion app/graph/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class MutationType < BaseObject
field :updateSource, mutation: SourceMutations::Update
field :destroySource, mutation: SourceMutations::Destroy

field :createTeamUser, mutation: TeamUserMutations::Create
field :updateTeamUser, mutation: TeamUserMutations::Update
field :destroyTeamUser, mutation: TeamUserMutations::Destroy

Expand Down
27 changes: 25 additions & 2 deletions app/graph/types/user_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ def get_send_failed_login_notifications
field :accepted_terms, GraphQL::Types::Boolean, null: true
field :last_accepted_terms_at, GraphQL::Types::String, null: true
field :team_ids, [GraphQL::Types::Int, null: true], null: true

field :user_teams, GraphQL::Types::String, null: true

def user_teams
User.current == object ? object.user_teams : {}.to_json
end

field :last_active_at, GraphQL::Types::Int, null: true
field :completed_signup, GraphQL::Types::Boolean, null: true

Expand All @@ -61,6 +67,10 @@ def is_admin

field :current_project, ProjectType, null: true

def current_project
User.current == object ? object.current_project : nil
end

field :confirmed, GraphQL::Types::Boolean, null: true

def confirmed
Expand All @@ -75,6 +85,10 @@ def source

field :current_team, TeamType, null: true

def current_team
User.current == object ? object.current_team : nil
end

field :bot, BotUserType, null: true

def bot
Expand All @@ -86,19 +100,26 @@ def bot
end

def team_user(team_slug:)
TeamUser
tu = TeamUser
.joins(:team)
.where("teams.slug" => team_slug, :user_id => object.id)
.last
TeamUser.find_if_can(tu.id, context[:ability])
end

field :teams, TeamType.connection_type, null: true

def teams
return Team.none unless object == User.current
object.teams
end

field :team_users, TeamUserType.connection_type, null: true do
argument :status, GraphQL::Types::String, required: false
end

def team_users(status: nil)
return TeamUser.none unless object == User.current
team_users = object.team_users
team_users = team_users.where(status: status) if status
team_users
Expand All @@ -109,6 +130,7 @@ def team_users(status: nil)
end

def annotations(type: nil)
return Annotation.none unless object == User.current
type.blank? ? object.annotations : object.annotations(type)
end

Expand All @@ -117,6 +139,7 @@ def annotations(type: nil)
end

def assignments(team_id: nil)
return ProjectMedia.none unless object == User.current
pms = Annotation.project_media_assigned_to_user(object).order("id DESC")
team_id = team_id.to_i
pms = pms.where(team_id: team_id) if team_id > 0
Expand All @@ -128,7 +151,7 @@ def assignments(team_id: nil)
field :feed_invitations, FeedInvitationType.connection_type, null: false

def feed_invitations
return FeedInvitation.none if object.email.blank?
return FeedInvitation.none if object.email.blank? || User.current != object
FeedInvitation.where(email: object.email)
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def current_team
end

def current_project
Project.where(id: self.current_project_id).last unless self.current_project_id.blank?
Project.where(id: self.current_project_id, team_id: self.current_team_id).last unless self.current_project_id.blank?
end

def user_teams
Expand Down
37 changes: 0 additions & 37 deletions lib/relay.idl
Original file line number Diff line number Diff line change
Expand Up @@ -2860,34 +2860,6 @@ type CreateTeamTaskPayload {
team_taskEdge: TeamTaskEdge
}

"""
Autogenerated input type of CreateTeamUser
"""
input CreateTeamUserInput {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
role: String
status: String!
team_id: Int!
user_id: Int!
}

"""
Autogenerated return type of CreateTeamUser
"""
type CreateTeamUserPayload {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
team: Team
team_user: TeamUser
team_userEdge: TeamUserEdge
user: User
}

"""
Autogenerated input type of CreateTiplineNewsletter
"""
Expand Down Expand Up @@ -9348,12 +9320,6 @@ type MutationType {
"""
input: CreateTeamTaskInput!
): CreateTeamTaskPayload
createTeamUser(
"""
Parameters for CreateTeamUser
"""
input: CreateTeamUserInput!
): CreateTeamUserPayload
createTiplineNewsletter(
"""
Parameters for CreateTiplineNewsletter
Expand Down Expand Up @@ -16004,9 +15970,6 @@ input UpdateTeamUserInput {
clientMutationId: String
id: ID
role: String
status: String
team_id: Int
user_id: Int
}

"""
Expand Down
Loading

0 comments on commit dc06b3b

Please sign in to comment.