diff --git a/api/app/graph/refinery/api/graphql_schema.rb b/api/app/graph/refinery/api/graphql_schema.rb index 78f91112e2..5c457b4dcf 100644 --- a/api/app/graph/refinery/api/graphql_schema.rb +++ b/api/app/graph/refinery/api/graphql_schema.rb @@ -4,7 +4,7 @@ module Refinery module Api GraphqlSchema = GraphQL::Schema.define do query Types::QueryType - # mutation Types::MutationType + mutation Types::MutationType resolve_type -> (obj, args, ctx) { type_name = obj.class.name diff --git a/api/app/graph/refinery/api/inputs/pages/page_input.rb b/api/app/graph/refinery/api/inputs/pages/page_input.rb new file mode 100644 index 0000000000..53b5c79f6f --- /dev/null +++ b/api/app/graph/refinery/api/inputs/pages/page_input.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Inputs + module Page + PageInput = GraphQL::InputObjectType.define do + name 'PageInput' + + input_field :parent_id, types.Int + input_field :path, types.String + input_field :show_in_menu, types.Boolean + input_field :link_url, types.String + input_field :menu_match, types.String + input_field :deletable, types.Boolean + input_field :draft, types.Boolean + input_field :skip_to_first_child, types.Boolean + input_field :lft, types.Int + input_field :rgt, types.Int + input_field :depth, types.Int + input_field :view_template, types.String + input_field :layout_template, types.String + input_field :locale, types.String + input_field :title, types.String + input_field :custom_slug, types.String + input_field :menu_title, types.String + input_field :slug, types.String + input_field :meta_description, types.String + input_field :browser_title, types.String + + input_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/inputs/pages/page_part_input.rb b/api/app/graph/refinery/api/inputs/pages/page_part_input.rb new file mode 100644 index 0000000000..8ca92e9286 --- /dev/null +++ b/api/app/graph/refinery/api/inputs/pages/page_part_input.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Inputs + module Page + PagePartInput = GraphQL::InputObjectType.define do + name 'PagePartInput' + + input_field :slug, types.String + input_field :position, types.Int + input_field :title, types.String + + input_field :locale, types.String + input_field :body, types.String + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/mutations/pages/page_mutations.rb b/api/app/graph/refinery/api/mutations/pages/page_mutations.rb new file mode 100644 index 0000000000..b1a6e8d321 --- /dev/null +++ b/api/app/graph/refinery/api/mutations/pages/page_mutations.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Mutations + module PageMutations + Create = GraphQL::Relay::Mutation.define do + name 'CreatePage' + description 'Create a page' + + input_field :page, !Inputs::Page::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 + + Update = GraphQL::Relay::Mutation.define do + name 'UpdatePage' + description 'Create a page' + + input_field :id, !types.ID + input_field :page, !Inputs::Page::PageInput + + return_field :page, Types::Page::PageType + + resolve -> (obj, inputs, ctx) { + inputs = inputs.to_h.deep_symbolize_keys + + Refinery::Page.update(inputs[:id], inputs[:page]) + + { page: page } + } + end + + Delete = GraphQL::Relay::Mutation.define do + name 'DeletePage' + + input_field :id, !types.ID + + return_field :page, Types::Page::PageType + + resolve -> (obj, inputs, ctx) { + page = Refinery::Page.destroy(inputs[:id]) + + { page: page } + } + end + end + end + end +end \ No newline at end of file diff --git a/api/app/graph/refinery/api/types/mutation_type.rb b/api/app/graph/refinery/api/types/mutation_type.rb new file mode 100644 index 0000000000..671e5f2a6c --- /dev/null +++ b/api/app/graph/refinery/api/types/mutation_type.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Refinery + module Api + module Types + MutationType = GraphQL::ObjectType.define do + 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 + end + end + end +end \ No newline at end of file