From e5138bdadab824f06f23b5c4779cd64561f81bd1 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Sun, 29 Oct 2017 23:36:59 -0400 Subject: [PATCH] Refactor Pages module --- .../graph/refinery/api/fields/page_field.rb | 19 --------- .../refinery/api/fields/pages/page_field.rb | 21 ++++++++++ .../refinery/api/fields/pages/pages_field.rb | 20 ++++++++++ .../refinery/api/types/page_part_type.rb | 21 ---------- api/app/graph/refinery/api/types/page_type.rb | 39 ------------------- .../api/types/pages/page_part_type.rb | 23 +++++++++++ .../refinery/api/types/pages/page_type.rb | 39 +++++++++++++++++++ .../graph/refinery/api/types/query_type.rb | 4 +- 8 files changed, 105 insertions(+), 81 deletions(-) delete mode 100644 api/app/graph/refinery/api/fields/page_field.rb create mode 100644 api/app/graph/refinery/api/fields/pages/page_field.rb create mode 100644 api/app/graph/refinery/api/fields/pages/pages_field.rb delete mode 100644 api/app/graph/refinery/api/types/page_part_type.rb delete mode 100644 api/app/graph/refinery/api/types/page_type.rb create mode 100644 api/app/graph/refinery/api/types/pages/page_part_type.rb create mode 100644 api/app/graph/refinery/api/types/pages/page_type.rb diff --git a/api/app/graph/refinery/api/fields/page_field.rb b/api/app/graph/refinery/api/fields/page_field.rb deleted file mode 100644 index 33b6b8eb95..0000000000 --- a/api/app/graph/refinery/api/fields/page_field.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -module Refinery - module Api - module Fields - PageField = GraphQL::Field.define do - name 'Page' - description 'Find a page by ID' - - type Types::PageType - argument :id, !types.ID - - resolve -> (obj, args, ctx) { - Refinery::Page.find_by_id(args[:id]) - } - end - end - end -end \ No newline at end of file diff --git a/api/app/graph/refinery/api/fields/pages/page_field.rb b/api/app/graph/refinery/api/fields/pages/page_field.rb new file mode 100644 index 0000000000..07b9992335 --- /dev/null +++ b/api/app/graph/refinery/api/fields/pages/page_field.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Fields + module Pages + PageField = GraphQL::Field.define do + name 'Page' + description 'Find a page by ID' + + type Types::Pages::PageType + argument :id, !types.ID + + resolve -> (obj, args, ctx) { + Refinery::Page.find_by_id(args[:id]) + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/fields/pages/pages_field.rb b/api/app/graph/refinery/api/fields/pages/pages_field.rb new file mode 100644 index 0000000000..cb1048503b --- /dev/null +++ b/api/app/graph/refinery/api/fields/pages/pages_field.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Fields + module Pages + PagesField = GraphQL::Field.define do + name 'Pages' + description 'Find all pages' + + type types[Types::Pages::PageType] + + resolve -> (obj, args, ctx) { + Refinery::Page.all + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/page_part_type.rb b/api/app/graph/refinery/api/types/page_part_type.rb deleted file mode 100644 index 6abe259214..0000000000 --- a/api/app/graph/refinery/api/types/page_part_type.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -module Refinery - module Api - module Types - PagePartType = GraphQL::ObjectType.define do - name "PagePart" - description "A PagePart" - - interfaces [Types::ActiveRecordInterface] - - field :slug, types.String - field :position, types.Int - field :title, types.String - - field :locale, types.String - field :body, types.String - end - end - end -end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/page_type.rb b/api/app/graph/refinery/api/types/page_type.rb deleted file mode 100644 index dc152b2e5d..0000000000 --- a/api/app/graph/refinery/api/types/page_type.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -module Refinery - module Api - module Types - PageType = GraphQL::ObjectType.define do - name "Page" - description "A Page" - - interfaces [Types::ActiveRecordInterface] - - field :parent_id, types.Int - field :path, types.String - field :show_in_menu, types.Boolean - field :link_url, types.String - field :menu_match, types.String - field :deletable, types.Boolean - field :draft, types.Boolean - field :skip_to_first_child, types.Boolean - field :lft, types.Int - field :rgt, types.Int - field :depth, types.Int - field :view_template, types.String - field :layout_template, types.String - - field :locale, types.String - field :title, types.String - field :custom_slug, types.String - field :menu_title, types.String - field :slug, types.String - - field :meta_description, types.String - field :browser_title, types.String - - field :parts, types[Types::PagePartType] - end - end - end -end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/pages/page_part_type.rb b/api/app/graph/refinery/api/types/pages/page_part_type.rb new file mode 100644 index 0000000000..fc5acc0a7f --- /dev/null +++ b/api/app/graph/refinery/api/types/pages/page_part_type.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + module Pages + PagePartType = GraphQL::ObjectType.define do + name "PagePart" + description "A PagePart" + + interfaces [Types::ActiveRecordInterface] + + field :slug, types.String + field :position, types.Int + field :title, types.String + + field :locale, types.String + field :body, types.String + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/pages/page_type.rb b/api/app/graph/refinery/api/types/pages/page_type.rb new file mode 100644 index 0000000000..d2867767f0 --- /dev/null +++ b/api/app/graph/refinery/api/types/pages/page_type.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + module Pages + PageType = GraphQL::ObjectType.define do + name "Page" + description "A Page" + + interfaces [Types::ActiveRecordInterface] + + field :parent_id, types.Int + field :path, types.String + field :show_in_menu, types.Boolean + field :link_url, types.String + field :menu_match, types.String + field :deletable, types.Boolean + field :draft, types.Boolean + field :skip_to_first_child, types.Boolean + field :lft, types.Int + field :rgt, types.Int + field :depth, types.Int + field :view_template, types.String + field :layout_template, types.String + field :locale, types.String + field :title, types.String + field :custom_slug, types.String + field :menu_title, types.String + field :slug, types.String + field :meta_description, types.String + field :browser_title, types.String + + field :parts, types[Types::Pages::PagePartType] + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/query_type.rb b/api/app/graph/refinery/api/types/query_type.rb index d915e598f1..475ebd5d0b 100644 --- a/api/app/graph/refinery/api/types/query_type.rb +++ b/api/app/graph/refinery/api/types/query_type.rb @@ -7,8 +7,8 @@ module Types name 'Query' description 'The query root of this schema' - field :page, field: Fields::PageField - # field :pages, field: Refinery::Api::Fields::PagesField + field :page, field: Fields::Pages::PageField + field :pages, field: Fields::Pages::PagesField end end end