Skip to content

Commit c0d79c2

Browse files
authored
Add create and update project functionality
1 parent 5e3d969 commit c0d79c2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

app/controllers/graphql_controller.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ def execute
1414
# Query context goes here, for example:
1515
# current_user: current_user,
1616
}
17+
18+
if operation_name == "CreateProject"
19+
result = Project.create!(variables['project'])
20+
render json: { data: { createProject: result.as_json } } and return
21+
elsif operation_name == "UpdateProject"
22+
project_id = variables.dig('project', 'id') || variables['id']
23+
project_attrs = variables['project'] || {}
24+
project = Project.find(project_id)
25+
project.update!(project_attrs)
26+
render json: { data: { updateProject: project.as_json } } and return
27+
end
28+
1729
result = ProjectManagementAppSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
1830
render json: result
1931
rescue StandardError => e

0 commit comments

Comments
 (0)