Skip to content

Commit

Permalink
WIP: Add mutations for pages
Browse files Browse the repository at this point in the history
  • Loading branch information
bricesanchez committed Nov 17, 2017
1 parent c7256f3 commit 4122641
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/app/graph/refinery/api/graphql_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Refinery
module Api
GraphqlSchema = GraphQL::Schema.define do
query Types::QueryType
# mutation Types::MutationType
mutation Types::MutationType

resolve_type -> (obj, args, ctx) {
type_name = obj.class.name
Expand Down
36 changes: 36 additions & 0 deletions api/app/graph/refinery/api/inputs/pages/page_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module Refinery
module Api
module Inputs
module Page
PageInput = GraphQL::InputObjectType.define do
name 'PageInput'

input_field :parent_id, types.Int
input_field :path, types.String
input_field :show_in_menu, types.Boolean
input_field :link_url, types.String
input_field :menu_match, types.String
input_field :deletable, types.Boolean
input_field :draft, types.Boolean
input_field :skip_to_first_child, types.Boolean
input_field :lft, types.Int
input_field :rgt, types.Int
input_field :depth, types.Int
input_field :view_template, types.String
input_field :layout_template, types.String
input_field :locale, types.String
input_field :title, types.String
input_field :custom_slug, types.String
input_field :menu_title, types.String
input_field :slug, types.String
input_field :meta_description, types.String
input_field :browser_title, types.String

input_field :parts, types[Types::Pages::PagePartType]
end
end
end
end
end
20 changes: 20 additions & 0 deletions api/app/graph/refinery/api/inputs/pages/page_part_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Refinery
module Api
module Inputs
module Page
PagePartInput = GraphQL::InputObjectType.define do
name 'PagePartInput'

input_field :slug, types.String
input_field :position, types.Int
input_field :title, types.String

input_field :locale, types.String
input_field :body, types.String
end
end
end
end
end
58 changes: 58 additions & 0 deletions api/app/graph/refinery/api/mutations/pages/page_mutations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

module Refinery
module Api
module Mutations
module PageMutations
Create = GraphQL::Relay::Mutation.define do
name 'CreatePage'
description 'Create a page'

input_field :page, !Inputs::Page::PageInput

return_field :page, Types::Pages::PageType

resolve -> (obj, inputs, ctx) {
inputs = inputs.to_h.deep_symbolize_keys

page = Refinery::Page.create!(inputs[:page])

{ page: page }
}
end

Update = GraphQL::Relay::Mutation.define do
name 'UpdatePage'
description 'Create a page'

input_field :id, !types.ID
input_field :page, !Inputs::Page::PageInput

return_field :page, Types::Page::PageType

resolve -> (obj, inputs, ctx) {
inputs = inputs.to_h.deep_symbolize_keys

Refinery::Page.update(inputs[:id], inputs[:page])

{ page: page }
}
end

Delete = GraphQL::Relay::Mutation.define do
name 'DeletePage'

input_field :id, !types.ID

return_field :page, Types::Page::PageType

resolve -> (obj, inputs, ctx) {
page = Refinery::Page.destroy(inputs[:id])

{ page: page }
}
end
end
end
end
end
16 changes: 16 additions & 0 deletions api/app/graph/refinery/api/types/mutation_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Refinery
module Api
module Types
MutationType = GraphQL::ObjectType.define do
name 'Mutation'
description 'The mutation root for this schema'

field :create_page, field: Mutations::Pages::PageMutations::Create.field
field :update_page, field: Mutations::Pages::PageMutations::Update.field
field :delete_page, field: Mutations::Pages::PageMutations::Delete.field
end
end
end
end

0 comments on commit 4122641

Please sign in to comment.