Skip to content

Commit

Permalink
WIP: Refactor graphql ruby with class name style
Browse files Browse the repository at this point in the history
  • Loading branch information
bricesanchez committed Jul 25, 2018
1 parent d17f717 commit a41520f
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 72 deletions.
2 changes: 1 addition & 1 deletion api/app/graph/refinery/api/fields/pages/page_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Refinery
module Api
module Fields
module Pages
PageField = GraphQL::Field.define do
class PageField < GraphQL::Schema::Field
name 'Page'
description 'Find a page by ID'

Expand Down
2 changes: 1 addition & 1 deletion api/app/graph/refinery/api/fields/pages/pages_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Refinery
module Api
module Fields
module Pages
PagesField = GraphQL::Field.define do
class PagesField < GraphQL::Schema::Field
name 'Pages'
description 'Find all pages'

Expand Down
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 @@ -2,7 +2,7 @@

module Refinery
module Api
GraphqlSchema = GraphQL::Schema.define do
class GraphqlSchema < GraphQL::Schema
query Types::QueryType
mutation Types::MutationType

Expand Down
2 changes: 1 addition & 1 deletion api/app/graph/refinery/api/inputs/pages/page_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Refinery
module Api
module Inputs
module Pages
PageInput = GraphQL::InputObjectType.define do
class PageInput < GraphQL::Schema::InputObject
name 'PageInput'

input_field :parent_id, types.Int
Expand Down
2 changes: 1 addition & 1 deletion api/app/graph/refinery/api/inputs/pages/page_part_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Refinery
module Api
module Inputs
module Pages
PagePartInput = GraphQL::InputObjectType.define do
class PagePartInput < GraphQL::Schema::InputObject
name 'PagePartInput'

input_field :slug, types.String
Expand Down
26 changes: 26 additions & 0 deletions api/app/graph/refinery/api/mutations/pages/create.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module Refinery
module Api
module Mutations
module Pages
class Create < GraphQL::Schema::Mutation
name 'CreatePage'
description 'Create a page'

input_field :page, !Inputs::Pages::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
end
end
end
end
23 changes: 23 additions & 0 deletions api/app/graph/refinery/api/mutations/pages/delete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Refinery
module Api
module Mutations
module Pages
class Delete < GraphQL::Schema::Mutation
name 'DeletePage'

input_field :id, !types.ID

return_field :page, Types::Pages::PageType

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

{ page: page }
}
end
end
end
end
end
60 changes: 0 additions & 60 deletions api/app/graph/refinery/api/mutations/pages/page_mutations.rb

This file was deleted.

27 changes: 27 additions & 0 deletions api/app/graph/refinery/api/mutations/pages/update.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Refinery
module Api
module Mutations
module Pages
class Update < GraphQL::Schema::Mutation
name 'UpdatePage'
description 'Create a page'

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

return_field :page, Types::Pages::PageType

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

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

{ page: page }
}
end
end
end
end
end
9 changes: 9 additions & 0 deletions api/app/graph/refinery/api/types/base_interface.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Refinery
module Api
module Types
class BaseInterface
include GraphQL::Schema::Interface
end
end
end
end
8 changes: 8 additions & 0 deletions api/app/graph/refinery/api/types/base_object.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Refinery
module Api
module Types
class BaseObject < GraphQL::Schema::Object
end
end
end
end
8 changes: 4 additions & 4 deletions api/app/graph/refinery/api/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
module Refinery
module Api
module Types
MutationType = GraphQL::ObjectType.define do
class MutationType < Types::BaseObject
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
field :createPage, mutation: Mutations::Pages::Create
field :updatePage, mutation: Mutations::Pages::Update
field :deletePage, mutation: Mutations::Pages::Delete
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion api/app/graph/refinery/api/types/pages/page_part_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Refinery
module Api
module Types
module Pages
PagePartType = GraphQL::ObjectType.define do
class PagePartType < GraphQL::Schema::Object
name "PagePart"
description "A PagePart"

Expand Down
2 changes: 1 addition & 1 deletion api/app/graph/refinery/api/types/pages/page_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Refinery
module Api
module Types
module Pages
PageType = GraphQL::ObjectType.define do
class PageType < GraphQL::Schema::Object
name "Page"
description "A Page"

Expand Down
2 changes: 1 addition & 1 deletion api/app/graph/refinery/api/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Refinery
module Api
module Types
QueryType = GraphQL::ObjectType.define do
class QueryType < Types::BaseObject
name 'Query'
description 'The query root of this schema'

Expand Down

0 comments on commit a41520f

Please sign in to comment.