-
Notifications
You must be signed in to change notification settings - Fork 5
Add Delete, Update mutations #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
168dcc2
Add Delete, Update mutations
patch0 d96ed86
Rubocop
patch0 bb88a44
Refactor CreateProjectInputType and CreateProject mutation
patch0 3183caa
Rubocop. again
patch0 9a1a839
Merge branch 'main' into add-update-delete-mutations
patch0 2cb9691
Merge branch 'rubocop-fixes' into add-update-delete-mutations
patch0 c3b28e4
Merge branch 'add-update-delete-mutations' of github.com:RaspberryPiF…
patch0 6718f17
Merge branch 'main' into add-update-delete-mutations
patch0 01912b6
Merge branch 'main' into add-update-delete-mutations
patch0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,31 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mutations | ||
| class DeleteProject < BaseMutation | ||
| description 'A mutation to delete an existing project' | ||
|
|
||
| argument :id, String, required: true, description: 'The ID of the project to delete' | ||
|
|
||
| field :id, String, 'The ID of the project that has been deleted' | ||
|
|
||
| def resolve(**input) | ||
| project = GlobalID.find(input[:id]) | ||
|
|
||
| raise GraphQL::ExecutionError, 'Project not found' unless project | ||
|
|
||
| unless context[:current_ability].can?(:destroy, project) | ||
| raise GraphQL::ExecutionError, 'You are not permitted to delete that project' | ||
| end | ||
|
|
||
| return { id: project.id } if project.destroy | ||
|
|
||
| raise GraphQL::ExecutionError, "Deletion failed for project #{project.identifier}" | ||
| end | ||
|
|
||
| def ready?(...) | ||
| return true if context[:current_ability]&.can?(:destroy, Project, user_id: context[:current_user_id]) | ||
|
|
||
| raise GraphQL::ExecutionError, 'You are not permitted to delete projects' | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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,31 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mutations | ||
| class UpdateProject < BaseMutation | ||
| description 'A mutation to update an existing project' | ||
|
|
||
| input_object_class Types::UpdateProjectInputType | ||
|
|
||
| field :project, Types::ProjectType, description: 'The project that has been updated' | ||
|
|
||
| def resolve(**input) | ||
| project = GlobalID.find(input[:id]) | ||
| raise GraphQL::ExecutionError, 'Project not found' unless project | ||
|
|
||
| unless context[:current_ability].can?(:update, project) | ||
| raise GraphQL::ExecutionError, | ||
| 'You are not permitted to update this project' | ||
| end | ||
|
|
||
| return { project: } if project.update(input.slice(:project_type, :name)) | ||
|
|
||
| raise GraphQL::ExecutionError, project.errors.full_messages.join(', ') | ||
| end | ||
|
|
||
| def ready?(**_args) | ||
| return true if context[:current_ability]&.can?(:update, Project, user_id: context[:current_user_id]) | ||
|
|
||
| raise GraphQL::ExecutionError, 'You are not permitted to update a project' | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 | ||
| class CreateProjectInputType < Types::BaseInputObject | ||
| description 'Represents a project during creation' | ||
|
|
||
| argument :components, [Types::ProjectComponentInputType], required: false, description: 'Any project components' | ||
| argument :name, String, required: true, description: 'The name of the project' | ||
| argument :project_type, String, required: true, description: 'The type of project, e.g. python, html' | ||
| end | ||
| end |
This file contains hidden or 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
4 changes: 1 addition & 3 deletions
4
app/graphql/types/component_input_type.rb → ...hql/types/project_component_input_type.rb
This file contains hidden or 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 |
|---|---|---|
| @@ -1,14 +1,12 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Types | ||
| class ComponentInputType < Types::BaseInputObject | ||
| class ProjectComponentInputType < Types::BaseInputObject | ||
| description 'Represents a project component during a mutation' | ||
|
|
||
| argument :content, String, required: false, description: 'The text content of the component' | ||
| argument :default, Boolean, required: true, description: 'If this is the default component on a project' | ||
| argument :extension, String, required: true, description: 'The file extension of the component, e.g. html, csv, py' | ||
| argument :name, String, required: true, description: 'The name of the file' | ||
| argument :project_id, ID, required: false, | ||
| description: 'The ID of the project this component should be assocated with' | ||
| end | ||
| end |
This file contains hidden or 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 | ||
| class UpdateProjectInputType < Types::BaseInputObject | ||
| description 'Represents a project during an update' | ||
|
|
||
| argument :id, String, required: true, description: 'The ID of the project to update' | ||
| argument :name, String, required: false, description: 'The name of the project' | ||
| argument :project_type, String, required: false, description: 'The type of project, e.g. python, html' | ||
| end | ||
| end |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oo this is nicer 👀