Skip to content

Commit

Permalink
Merge pull request #822 from kevinhughes27/graphql-types
Browse files Browse the repository at this point in the history
generate types from graphql queries
  • Loading branch information
kevinhughes27 committed Jul 30, 2018
2 parents ec56eef + a0981eb commit 6a93e8c
Show file tree
Hide file tree
Showing 74 changed files with 578 additions and 531 deletions.
24 changes: 19 additions & 5 deletions app/controllers/admin/divisions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ def create
}"
)

@division = Division.new(result_to_attributes(result, 'division', except: 'bracket'))
@division.bracket_type = result['division']['bracket']['handle']
@division = if result['division']
division = Division.new(result_to_attributes(result, 'division', except: 'bracket'))
division.bracket_type = result['division']['bracket']['handle']
division
else
Division.new(division_params)
end

@errors = result_to_errors(result)

if result['success']
Expand All @@ -43,7 +49,7 @@ def create
end

def update
input = params_to_input(division_params, params, 'division_id')
input = params_to_input(division_params, params)

result = execute_graphql(
'updateDivision',
Expand Down Expand Up @@ -74,7 +80,7 @@ def update
end

def destroy
input = params_to_input({}, params, 'division_id')
input = params_to_input({}, params)

result = execute_graphql(
'deleteDivision',
Expand Down Expand Up @@ -126,7 +132,15 @@ def seed
private

def load_division
@division = @tournament.divisions.includes(:teams, games: [:home, :away, :score_reports, :score_disputes]).find(params[:id])
@division = @tournament.divisions.includes(
:teams,
games: [
:home,
:away,
:score_reports,
:score_disputes
]
).find(params[:id])
end

def division_params
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/fields_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def update
end

def destroy
input = params_to_input({}, params, 'field_id')
input = params_to_input({}, params)

result = execute_graphql(
'deleteField',
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/teams_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create
end

def update
input = params_to_input(team_params, params, 'teamId')
input = params_to_input(team_params, params)
input['name'] = input['name'].to_s if input['name']
input['phone'] = input['phone'].to_s if input['phone']

Expand Down Expand Up @@ -62,7 +62,7 @@ def update
end

def destroy
input = params_to_input({}, params, 'teamId')
input = params_to_input({}, params)

result = execute_graphql(
'deleteTeam',
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def params_to_input(strong_params, params = {}, id_key = nil)
end

# add id as an integer with full id_key
id_key ||= 'id'
input[id_key] = params[:id].to_i if params[:id].present?

# add confirm param as proper boolean
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/inputs/delete_division_input.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Inputs::DeleteDivisionInput < Inputs::BaseInputObject
argument :divisionId, ID, required: true
argument :id, ID, required: true
argument :confirm, Boolean, required: false
end
2 changes: 1 addition & 1 deletion app/graphql/inputs/delete_field_input.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Inputs::DeleteFieldInput < Inputs::BaseInputObject
argument :fieldId, ID, required: true
argument :id, ID, required: true
argument :confirm, Boolean, required: false
end
2 changes: 1 addition & 1 deletion app/graphql/inputs/delete_team_input.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Inputs::DeleteTeamInput < Inputs::BaseInputObject
argument :teamId, ID, required: true
argument :id, ID, required: true
argument :confirm, Boolean, required: false
end
2 changes: 1 addition & 1 deletion app/graphql/inputs/update_division_input.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Inputs::UpdateDivisionInput < Inputs::BaseInputObject
argument :divisionId, ID, required: true
argument :id, ID, required: true
argument :name, String, required: false
argument :numTeams, Int, required: false
argument :numDays, Int, required: false
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/inputs/update_field_input.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Inputs::UpdateFieldInput < Inputs::BaseInputObject
argument :fieldId, ID, required: true
argument :id, ID, required: true
argument :name, String, required: false
argument :lat, Float, required: false
argument :long, Float, required: false
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/inputs/update_team_input.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Inputs::UpdateTeamInput < Inputs::BaseInputObject
argument :teamId, ID, required: true
argument :id, ID, required: true
argument :name, String, required: false
argument :email, String, required: false
argument :phone, String, required: false
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/mutations/create_division.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Mutations::CreateDivision < Mutations::BaseMutation

argument :input, Inputs::CreateDivisionInput, required: true

field :division, Types::Division, null: false
field :division, Types::Division, null: true
field :success, Boolean, null: false
field :message, String, null: true
field :userErrors, [Types::Error], null: true
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/mutations/create_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Mutations::CreateField < Mutations::BaseMutation

argument :input, Inputs::CreateFieldInput, required: true

field :field, Types::Field, null: false
field :field, Types::Field, null: true
field :success, Boolean, null: false
field :message, String, null: true
field :userErrors, [Types::Error], null: true
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/mutations/create_team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Mutations::CreateTeam < Mutations::BaseMutation

argument :input, Inputs::CreateTeamInput, required: true

field :team, Types::Team, null: false
field :team, Types::Team, null: true
field :success, Boolean, null: false
field :message, String, null: true
field :userErrors, [Types::Error], null: true
Expand Down
1 change: 0 additions & 1 deletion app/graphql/resolvers/create_division.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def call(inputs, ctx)
else
{
success: false,
division: @division,
user_errors: @division.fields_errors
}
end
Expand Down
1 change: 0 additions & 1 deletion app/graphql/resolvers/create_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def call(inputs, ctx)
{
success: false,
user_errors: field.fields_errors,
field: field
}
end
end
Expand Down
3 changes: 1 addition & 2 deletions app/graphql/resolvers/create_team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ def call(inputs, ctx)
{
success: true,
message: 'Team created',
team: team
team: team,
}
else
{
success: false,
user_errors: team.fields_errors,
team: team
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/resolvers/delete_division.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Resolvers::DeleteDivision < Resolvers::BaseResolver
Are you sure this is what you want to do?"""

def call(inputs, ctx)
division = ctx[:tournament].divisions.find(inputs[:division_id])
division = ctx[:tournament].divisions.find(inputs[:id])

if !(inputs[:confirm] || division.safe_to_delete?)
{
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/resolvers/delete_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Resolvers::DeleteField < Resolvers::BaseResolver
is in progress this is probably not something you want to do."""

def call(inputs, ctx)
field = ctx[:tournament].fields.find(inputs[:field_id])
field = ctx[:tournament].fields.find(inputs[:id])

if !(inputs[:confirm] || field.safe_to_delete?)
return {
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/resolvers/delete_team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Resolvers::DeleteTeam < Resolvers::BaseResolver
division_name division first."""

def call(inputs, ctx)
team = ctx[:tournament].teams.find(inputs[:team_id])
team = ctx[:tournament].teams.find(inputs[:id])

if !team.allow_delete?
return {
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/resolvers/update_division.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Resolvers::UpdateDivision < Resolvers::BaseResolver
def call(inputs, ctx)
@tournament = ctx[:tournament]
@division = @tournament.divisions.find(inputs[:division_id])
@division = @tournament.divisions.find(inputs[:id])
params = inputs.to_h.except(:division_id, :confirm)

@division.assign_attributes(params)
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/resolvers/update_field.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Resolvers::UpdateField < Resolvers::BaseResolver
def call(inputs, ctx)
field = ctx[:tournament].fields.find(inputs[:field_id])
field = ctx[:tournament].fields.find(inputs[:id])

params = inputs.to_h.except(:field_id)

Expand Down
4 changes: 3 additions & 1 deletion app/graphql/resolvers/update_team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Resolvers::UpdateTeam < Resolvers::BaseResolver
the division_name division first."""

def call(inputs, ctx)
team = ctx[:tournament].teams.find(inputs[:team_id])
team = ctx[:tournament].teams.find(inputs[:id])
params = inputs.to_h.except(:team_id, :confirm)

team.assign_attributes(params)
Expand Down Expand Up @@ -41,6 +41,8 @@ def call(inputs, ctx)
team: team
}
else
# remove after admin_next ships
team.name ||= ""
{
success: false,
user_errors: team.fields_errors,
Expand Down
Loading

0 comments on commit 6a93e8c

Please sign in to comment.