Skip to content

Commit a41520f

Browse files
committed
WIP: Refactor graphql ruby with class name style
1 parent d17f717 commit a41520f

15 files changed

Lines changed: 105 additions & 72 deletions

File tree

api/app/graph/refinery/api/fields/pages/page_field.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
module Fields
66
module Pages
7-
PageField = GraphQL::Field.define do
7+
class PageField < GraphQL::Schema::Field
88
name 'Page'
99
description 'Find a page by ID'
1010

api/app/graph/refinery/api/fields/pages/pages_field.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
module Fields
66
module Pages
7-
PagesField = GraphQL::Field.define do
7+
class PagesField < GraphQL::Schema::Field
88
name 'Pages'
99
description 'Find all pages'
1010

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Refinery
44
module Api
5-
GraphqlSchema = GraphQL::Schema.define do
5+
class GraphqlSchema < GraphQL::Schema
66
query Types::QueryType
77
mutation Types::MutationType
88

api/app/graph/refinery/api/inputs/pages/page_input.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
module Inputs
66
module Pages
7-
PageInput = GraphQL::InputObjectType.define do
7+
class PageInput < GraphQL::Schema::InputObject
88
name 'PageInput'
99

1010
input_field :parent_id, types.Int

api/app/graph/refinery/api/inputs/pages/page_part_input.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
module Inputs
66
module Pages
7-
PagePartInput = GraphQL::InputObjectType.define do
7+
class PagePartInput < GraphQL::Schema::InputObject
88
name 'PagePartInput'
99

1010
input_field :slug, types.String
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
module Refinery
4+
module Api
5+
module Mutations
6+
module Pages
7+
class Create < GraphQL::Schema::Mutation
8+
name 'CreatePage'
9+
description 'Create a page'
10+
11+
input_field :page, !Inputs::Pages::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+
end
24+
end
25+
end
26+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
module Refinery
4+
module Api
5+
module Mutations
6+
module Pages
7+
class Delete < GraphQL::Schema::Mutation
8+
name 'DeletePage'
9+
10+
input_field :id, !types.ID
11+
12+
return_field :page, Types::Pages::PageType
13+
14+
resolve -> (obj, inputs, ctx) {
15+
page = Refinery::Page.destroy(inputs[:id])
16+
17+
{ page: page }
18+
}
19+
end
20+
end
21+
end
22+
end
23+
end

api/app/graph/refinery/api/mutations/pages/page_mutations.rb

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
module Refinery
4+
module Api
5+
module Mutations
6+
module Pages
7+
class Update < GraphQL::Schema::Mutation
8+
name 'UpdatePage'
9+
description 'Create a page'
10+
11+
input_field :id, !types.ID
12+
input_field :page, !Inputs::Pages::PageInput
13+
14+
return_field :page, Types::Pages::PageType
15+
16+
resolve -> (obj, inputs, ctx) {
17+
inputs = inputs.to_h.deep_symbolize_keys
18+
19+
page = Refinery::Page.update(inputs[:id], inputs[:page])
20+
21+
{ page: page }
22+
}
23+
end
24+
end
25+
end
26+
end
27+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Refinery
2+
module Api
3+
module Types
4+
class BaseInterface
5+
include GraphQL::Schema::Interface
6+
end
7+
end
8+
end
9+
end

0 commit comments

Comments
 (0)