Skip to content

Commit

Permalink
WIP: Update to GraphQL 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
bricesanchez committed Sep 5, 2018
1 parent a485588 commit e143161
Show file tree
Hide file tree
Showing 23 changed files with 141 additions and 138 deletions.
21 changes: 0 additions & 21 deletions api/app/graph/refinery/api/fields_deprecated/pages/page_field.rb

This file was deleted.

20 changes: 0 additions & 20 deletions api/app/graph/refinery/api/fields_deprecated/pages/pages_field.rb

This file was deleted.

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 @@ -3,7 +3,7 @@
module Refinery
module Api
class GraphqlSchema < GraphQL::Schema
# mutation Types::MutationType
mutation Types::MutationType
query Types::QueryType
end
end
Expand Down
36 changes: 0 additions & 36 deletions api/app/graph/refinery/api/inputs/pages/page_input.rb

This file was deleted.

20 changes: 0 additions & 20 deletions api/app/graph/refinery/api/inputs/pages/page_part_input.rb

This file was deleted.

31 changes: 20 additions & 11 deletions api/app/graph/refinery/api/mutations/pages/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@ module Refinery
module Api
module Mutations
module Pages
class Create < GraphQL::Schema::Mutation
graphql_name 'CreatePage'
description 'Create a page'

argument :page, !Types::Pages::PageType
class Create < Mutations::BaseMutation
null true

type Types::Pages::PageType
graphql_name 'CreatePage'
description 'Create a Page'

resolve -> (obj, inputs, ctx) {
inputs = inputs.to_h.deep_symbolize_keys
field :page, Types::Pages::PageAttributes, null: true
field :errors, [String], null: false

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

{ page: page }
}
if page.errors.empty?
{
page: page,
errors: []
}
else
{
page: nil,
errors: page.errors.full_messages
}
end
end
end
end
end
Expand Down
22 changes: 17 additions & 5 deletions api/app/graph/refinery/api/mutations/pages/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,30 @@ module Refinery
module Api
module Mutations
module Pages
class Delete < Mutations::BaseMutation
class Delete < Mutations::BaseMutation
graphql_name 'DeletePage'
description 'Delete a Page'

argument :id, ID, required: true

return_field :page, Types::Pages::PageType
field :page, Types::Pages::PageType, null: false
field :errors, [String], null: false

resolve -> (id:) {
def resolve(id:)
page = Refinery::Page.destroy!(id)

{ page: page }
}
if page.errors.empty?
{
page: page,
errors: []
}
else
{
page: nil,
errors: page.errors.full_messages
}
end
end
end
end
end
Expand Down
30 changes: 19 additions & 11 deletions api/app/graph/refinery/api/mutations/pages/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@ module Refinery
module Api
module Mutations
module Pages
class Update < GraphQL::Schema::Mutation
class Update < Mutations::BaseMutation
graphql_name 'UpdatePage'
description 'Create a page'
description 'Update a Page'

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

return_field :page, Types::Pages::PageType
field :page, Types::Pages::PageType, null: false
field :errors, [String], null: false

resolve -> (obj, inputs, ctx) {
inputs = inputs.to_h.deep_symbolize_keys
def resolve(id:, page:)
page = Refinery::Page.update(id, page)

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

{ page: page }
}
if page.errors.empty?
{
page: page,
errors: []
}
else
{
page: nil,
errors: page.errors.full_messages
}
end
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions api/app/graph/refinery/api/resolvers/pages/page_resolver.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Refinery
module Api
module Resolvers
Expand Down
2 changes: 2 additions & 0 deletions api/app/graph/refinery/api/types/base_enum.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Refinery
module Api
module Types
Expand Down
2 changes: 2 additions & 0 deletions api/app/graph/refinery/api/types/base_input_object.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Refinery
module Api
module Types
Expand Down
2 changes: 2 additions & 0 deletions api/app/graph/refinery/api/types/base_interface.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Refinery
module Api
module Types
Expand Down
2 changes: 2 additions & 0 deletions api/app/graph/refinery/api/types/base_object.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Refinery
module Api
module Types
Expand Down
2 changes: 2 additions & 0 deletions api/app/graph/refinery/api/types/base_union.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Refinery
module Api
module Types
Expand Down
38 changes: 38 additions & 0 deletions api/app/graph/refinery/api/types/pages/page_attributes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

module Refinery
module Api
module Types
module Pages
class PageAttributes < Types::BaseInputObject
description "Attributes for creating or updating a page"

argument :parent_id, Integer, required: false
argument :path, String, required: false
argument :show_in_menu, Boolean, required: false
argument :link_url, String, required: false
argument :menu_match, String, required: false
argument :deletable, Boolean, required: false
argument :draft, Boolean, required: false
argument :skip_to_first_child, Boolean, required: false
argument :lft, Integer, required: false
argument :rgt, required: false
argument :depth, Integer, required: false
argument :view_template, String, required: false
argument :layout_template, String, required: false
argument :locale, String, required: false
argument :title, String, required: false
argument :custom_slug, String, required: false
argument :menu_title, String, required: false
argument :slug, String, required: false
argument :meta_description, String, required: false
argument :browser_title, String, required: false

argument :parts, [Types::PagePart], required: false
end
end
end
end
end


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

module Refinery
module Api
module Types
module Pages
class PagePartAttributes < Types::BaseInputObject
description "Attributes for creating or updating a page part"

argument :slug, String, required: false
argument :position, Integer, required: false
argument :title, String, required: false

argument :locale, String, required: false
argument :body, String, required: false
end
end
end
end
end
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 @@ -14,9 +14,9 @@ class QueryType < Types::BaseObject

field :page, Types::Pages::PageType,
null: true, resolve: Resolvers::Pages::PageResolver::ById do
argument :id, ID, required: true
description "Find page by id"
end

end
end
end
Expand Down
8 changes: 4 additions & 4 deletions api/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Refinery::Core::Engine.routes.draw do
namespace :api do
post '/graphql', to: 'graphql#execute'
end

if Rails.env.development?
mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: "/#{Refinery::Core.backend_route}/graphql"
end
if Rails.env.development?
mount GraphiQL::Rails::Engine, at: "/#{Refinery::Core.backend_route}/api/graphiql", graphql_path: '/api/graphql'
end
end
end
1 change: 1 addition & 0 deletions api/lib/refinery/api.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'refinerycms-core'
require 'graphql'
require 'graphiql/rails'

module Refinery
module Api
Expand Down
2 changes: 1 addition & 1 deletion api/refinerycms-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ Gem::Specification.new do |s|
# Runtime dependencies
s.add_dependency 'refinerycms-core', version
s.add_dependency 'graphql', '~> 1.8', '>= 1.8.5'
s.add_dependency 'graphiql-rails', '~> 1.4'

# Development dependencies (usually used for testing)
s.add_development_dependency 'refinerycms-testing', '~> 4.0.0'
s.add_development_dependency 'graphiql-rails', '~> 1.4'

s.required_ruby_version = Refinery::Version.required_ruby_version

Expand Down
Loading

0 comments on commit e143161

Please sign in to comment.