Skip to content

Commit

Permalink
Fix mutations for 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
bricesanchez committed Sep 12, 2018
1 parent 684c238 commit 245eeb0
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 43 deletions.
8 changes: 4 additions & 4 deletions api/app/graph/refinery/api/mutations/pages/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ module Api
module Mutations
module Pages
class Create < Mutations::BaseMutation
null true

graphql_name 'CreatePage'
description 'Create a Page'

field :page, Types::Pages::PageAttributes, null: true
argument :page, Types::Pages::PageAttributes, required: true

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

def resolve(page:)
page = Refinery::Page.create!(page)
page = Refinery::Page.create!(page.to_h)

if page.errors.empty?
{
Expand Down
4 changes: 2 additions & 2 deletions api/app/graph/refinery/api/mutations/pages/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class Delete < Mutations::BaseMutation

argument :id, ID, required: true

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

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

if page.errors.empty?
{
Expand Down
3 changes: 2 additions & 1 deletion api/app/graph/refinery/api/mutations/pages/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ class Update < Mutations::BaseMutation
description 'Update a Page'

argument :id, ID, required: true
argument :page, Types::Pages::PageAttributes, required: true

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

def resolve(id:, page:)
page = Refinery::Page.update(id, page)
page = Refinery::Page.update(id, page.to_h)

if page.errors.empty?
{
Expand Down
1 change: 1 addition & 0 deletions api/app/graph/refinery/api/types/pages/page_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class PageType < GraphQL::Schema::Object
graphql_name "Page"
description "A Page"

field :id, Integer, null: false
field :parent_id, Integer, null: true
field :path, String, null: true
field :show_in_menu, Boolean, null: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ module Pages
end

let(:query_string) do
<<-QUERY
mutation {
createPage(page: $page) {
page {
title
}
}
}
<<~QUERY
mutation createPage($input: CreatePageInput!) {
createPage(input: $input) {
page {
title
}
}
}
QUERY
end

Expand All @@ -37,17 +37,17 @@ module Pages
context 'create a page' do
let(:variables) do
{
'page' => {
'page' => {
'title' => 'Test page'
"input": {
"page": {
"title": "Test page"
}
}
}
end

it 'returns the page title of the newly created page' do
subject
expect(result['data']['create_page']['page']['title']).to eq('Test page')
expect(result['data']['createPage']['page']['title']).to eq('Test page')
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,30 @@ module Pages
end

let(:query_string) do
<<-QUERY
mutation($page: DeletePageInput!) {
deletePage(input: $page) {
page {
id
}
}
}
<<~QUERY
mutation deletePage($input: DeletePageInput!) {
deletePage(input: $input) {
page {
id
}
}
}
QUERY
end

subject { result }

context 'Correct page id' do
let(:variables) { {'page' => { 'id' => page.id }} }
let(:variables) do
{
"input": {
"id": page.id
}
}
end

it 'deletes the page' do
subject
expect(Refinery::Page.find_by_id(page.id)).to be(nil)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ module Pages
end

let(:query_string) do
<<-QUERY
mutation($page: UpdatePageInput!) {
updatePage(input: $page) {
page {
id
title
}
}
}
<<~QUERY
mutation updatePage($input: UpdatePageInput!) {
updatePage(input: $input) {
page {
id
title
}
}
}
QUERY
end

Expand All @@ -40,19 +40,19 @@ module Pages
context 'update a page' do
let(:variables) do
{
'page' => {
'id' => page.id,
'page' => {
'title' => 'Updated Test page'
"input": {
"id": page.id,
"page": {
"title": "Updated test page"
}
}
}
end

it 'returns the page id and title of the newly created page' do
subject
expect(result['data']['update_page']['page']['id']).to eq(page.id.to_s)
expect(result['data']['update_page']['page']['title']).to eq('Updated Test page')
expect(result['data']['updatePage']['page']['id']).to eq(page.id)
expect(result['data']['updatePage']['page']['title']).to eq('Updated test page')
end
end
end
Expand Down

0 comments on commit 245eeb0

Please sign in to comment.