Skip to content

Commit 4122641

Browse files
committed
WIP: Add mutations for pages
1 parent c7256f3 commit 4122641

File tree

5 files changed

+131
-1
lines changed

5 files changed

+131
-1
lines changed

api/app/graph/refinery/api/graphql_schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Refinery
44
module Api
55
GraphqlSchema = GraphQL::Schema.define do
66
query Types::QueryType
7-
# mutation Types::MutationType
7+
mutation Types::MutationType
88

99
resolve_type -> (obj, args, ctx) {
1010
type_name = obj.class.name
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
module Refinery
4+
module Api
5+
module Inputs
6+
module Page
7+
PageInput = GraphQL::InputObjectType.define do
8+
name 'PageInput'
9+
10+
input_field :parent_id, types.Int
11+
input_field :path, types.String
12+
input_field :show_in_menu, types.Boolean
13+
input_field :link_url, types.String
14+
input_field :menu_match, types.String
15+
input_field :deletable, types.Boolean
16+
input_field :draft, types.Boolean
17+
input_field :skip_to_first_child, types.Boolean
18+
input_field :lft, types.Int
19+
input_field :rgt, types.Int
20+
input_field :depth, types.Int
21+
input_field :view_template, types.String
22+
input_field :layout_template, types.String
23+
input_field :locale, types.String
24+
input_field :title, types.String
25+
input_field :custom_slug, types.String
26+
input_field :menu_title, types.String
27+
input_field :slug, types.String
28+
input_field :meta_description, types.String
29+
input_field :browser_title, types.String
30+
31+
input_field :parts, types[Types::Pages::PagePartType]
32+
end
33+
end
34+
end
35+
end
36+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
module Refinery
4+
module Api
5+
module Inputs
6+
module Page
7+
PagePartInput = GraphQL::InputObjectType.define do
8+
name 'PagePartInput'
9+
10+
input_field :slug, types.String
11+
input_field :position, types.Int
12+
input_field :title, types.String
13+
14+
input_field :locale, types.String
15+
input_field :body, types.String
16+
end
17+
end
18+
end
19+
end
20+
end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# frozen_string_literal: true
2+
3+
module Refinery
4+
module Api
5+
module Mutations
6+
module PageMutations
7+
Create = GraphQL::Relay::Mutation.define do
8+
name 'CreatePage'
9+
description 'Create a page'
10+
11+
input_field :page, !Inputs::Page::PageInput
12+
13+
return_field :page, Types::Pages::PageType
14+
15+
resolve -> (obj, inputs, ctx) {
16+
inputs = inputs.to_h.deep_symbolize_keys
17+
18+
page = Refinery::Page.create!(inputs[:page])
19+
20+
{ page: page }
21+
}
22+
end
23+
24+
Update = GraphQL::Relay::Mutation.define do
25+
name 'UpdatePage'
26+
description 'Create a page'
27+
28+
input_field :id, !types.ID
29+
input_field :page, !Inputs::Page::PageInput
30+
31+
return_field :page, Types::Page::PageType
32+
33+
resolve -> (obj, inputs, ctx) {
34+
inputs = inputs.to_h.deep_symbolize_keys
35+
36+
Refinery::Page.update(inputs[:id], inputs[:page])
37+
38+
{ page: page }
39+
}
40+
end
41+
42+
Delete = GraphQL::Relay::Mutation.define do
43+
name 'DeletePage'
44+
45+
input_field :id, !types.ID
46+
47+
return_field :page, Types::Page::PageType
48+
49+
resolve -> (obj, inputs, ctx) {
50+
page = Refinery::Page.destroy(inputs[:id])
51+
52+
{ page: page }
53+
}
54+
end
55+
end
56+
end
57+
end
58+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module Refinery
4+
module Api
5+
module Types
6+
MutationType = GraphQL::ObjectType.define do
7+
name 'Mutation'
8+
description 'The mutation root for this schema'
9+
10+
field :create_page, field: Mutations::Pages::PageMutations::Create.field
11+
field :update_page, field: Mutations::Pages::PageMutations::Update.field
12+
field :delete_page, field: Mutations::Pages::PageMutations::Delete.field
13+
end
14+
end
15+
end
16+
end

0 commit comments

Comments
 (0)