diff --git a/backend/lib/edgehog/devices/devices.ex b/backend/lib/edgehog/devices/devices.ex index 7266374df..4b3fcd4eb 100644 --- a/backend/lib/edgehog/devices/devices.ex +++ b/backend/lib/edgehog/devices/devices.ex @@ -29,6 +29,7 @@ defmodule Edgehog.Devices do ] graphql do + root_level_errors? true end resources do diff --git a/backend/lib/edgehog/tenants/tenants.ex b/backend/lib/edgehog/tenants/tenants.ex index ccdf4a5d9..a9a832919 100644 --- a/backend/lib/edgehog/tenants/tenants.ex +++ b/backend/lib/edgehog/tenants/tenants.ex @@ -23,6 +23,7 @@ defmodule Edgehog.Tenants do extensions: [AshGraphql.Api, AshJsonApi.Api] graphql do + root_level_errors? true end json_api do diff --git a/backend/test/edgehog_web/schema/mutation/create_hardware_type_test.exs b/backend/test/edgehog_web/schema/mutation/create_hardware_type_test.exs index d896e129e..ced35f4e8 100644 --- a/backend/test/edgehog_web/schema/mutation/create_hardware_type_test.exs +++ b/backend/test/edgehog_web/schema/mutation/create_hardware_type_test.exs @@ -59,7 +59,7 @@ defmodule EdgehogWeb.Schema.Mutation.CreateHardwareTypeTest do handle: "123Invalid$" ) - assert %{"fields" => ["handle"], "message" => "should only contain" <> _} = + assert %{fields: [:handle], message: "should only contain" <> _} = extract_error!(result) end @@ -70,7 +70,7 @@ defmodule EdgehogWeb.Schema.Mutation.CreateHardwareTypeTest do part_numbers: [] ) - assert %{"fields" => ["part_numbers"], "message" => "must have 1 or more items"} = + assert %{fields: [:part_numbers], message: "must have 1 or more items"} = extract_error!(result) end @@ -83,7 +83,7 @@ defmodule EdgehogWeb.Schema.Mutation.CreateHardwareTypeTest do name: fixture.name ) - assert %{"fields" => ["name"], "message" => "has already been taken"} = + assert %{fields: [:name], message: "has already been taken"} = extract_error!(result) end @@ -96,7 +96,7 @@ defmodule EdgehogWeb.Schema.Mutation.CreateHardwareTypeTest do handle: fixture.handle ) - assert %{"fields" => ["handle"], "message" => "has already been taken"} = + assert %{fields: [:handle], message: "has already been taken"} = extract_error!(result) end @@ -132,13 +132,6 @@ defmodule EdgehogWeb.Schema.Mutation.CreateHardwareTypeTest do partNumber } } - errors { - code - fields - message - shortMessage - vars - } } } """ @@ -160,12 +153,8 @@ defmodule EdgehogWeb.Schema.Mutation.CreateHardwareTypeTest do defp extract_error!(result) do assert %{ - data: %{ - "createHardwareType" => %{ - "result" => nil, - "errors" => [error] - } - } + data: nil, + errors: [error] } = result error @@ -178,8 +167,7 @@ defmodule EdgehogWeb.Schema.Mutation.CreateHardwareTypeTest do assert %{ data: %{ "createHardwareType" => %{ - "result" => hardware_type, - "errors" => [] + "result" => hardware_type } } } = result diff --git a/backend/test/edgehog_web/schema/mutation/delete_hardware_type_test.exs b/backend/test/edgehog_web/schema/mutation/delete_hardware_type_test.exs index b13920e52..5122d2763 100644 --- a/backend/test/edgehog_web/schema/mutation/delete_hardware_type_test.exs +++ b/backend/test/edgehog_web/schema/mutation/delete_hardware_type_test.exs @@ -42,7 +42,7 @@ defmodule EdgehogWeb.Schema.Mutation.DeleteHardwareTypeTest do test "fails with non-existing id", %{tenant: tenant} do result = delete_hardware_type_mutation(tenant: tenant, id: 123_789) - assert %{"fields" => ["id"], "message" => "could not be found"} = extract_error!(result) + assert %{fields: [:id], message: "could not be found"} = extract_error!(result) end end @@ -53,13 +53,6 @@ defmodule EdgehogWeb.Schema.Mutation.DeleteHardwareTypeTest do result { id } - errors { - code - fields - message - shortMessage - vars - } } } """ @@ -76,12 +69,8 @@ defmodule EdgehogWeb.Schema.Mutation.DeleteHardwareTypeTest do defp extract_error!(result) do assert %{ - data: %{ - "deleteHardwareType" => %{ - "result" => nil, - "errors" => [error] - } - } + data: nil, + errors: [error] } = result error @@ -94,8 +83,7 @@ defmodule EdgehogWeb.Schema.Mutation.DeleteHardwareTypeTest do assert %{ data: %{ "deleteHardwareType" => %{ - "result" => hardware_type, - "errors" => [] + "result" => hardware_type } } } = result diff --git a/backend/test/edgehog_web/schema/mutation/update_hardware_type_test.exs b/backend/test/edgehog_web/schema/mutation/update_hardware_type_test.exs index 92de0f30e..4c31b1f9f 100644 --- a/backend/test/edgehog_web/schema/mutation/update_hardware_type_test.exs +++ b/backend/test/edgehog_web/schema/mutation/update_hardware_type_test.exs @@ -110,7 +110,7 @@ defmodule EdgehogWeb.Schema.Mutation.UpdateHardwareTypeTest do handle: "123Invalid$" ) - assert %{"fields" => ["handle"], "message" => "should only contain" <> _} = + assert %{fields: [:handle], message: "should only contain" <> _} = extract_error!(result) end @@ -122,7 +122,7 @@ defmodule EdgehogWeb.Schema.Mutation.UpdateHardwareTypeTest do part_numbers: [] ) - assert %{"fields" => ["part_numbers"], "message" => "must have 1 or more items"} = + assert %{fields: [:part_numbers], message: "must have 1 or more items"} = extract_error!(result) end @@ -136,7 +136,7 @@ defmodule EdgehogWeb.Schema.Mutation.UpdateHardwareTypeTest do name: fixture.name ) - assert %{"fields" => ["name"], "message" => "has already been taken"} = + assert %{fields: [:name], message: "has already been taken"} = extract_error!(result) end @@ -150,7 +150,7 @@ defmodule EdgehogWeb.Schema.Mutation.UpdateHardwareTypeTest do handle: fixture.handle ) - assert %{"fields" => ["handle"], "message" => "has already been taken"} = + assert %{fields: [:handle], message: "has already been taken"} = extract_error!(result) end @@ -190,13 +190,6 @@ defmodule EdgehogWeb.Schema.Mutation.UpdateHardwareTypeTest do partNumber } } - errors { - code - fields - message - shortMessage - vars - } } } """ @@ -222,12 +215,8 @@ defmodule EdgehogWeb.Schema.Mutation.UpdateHardwareTypeTest do defp extract_error!(result) do assert %{ - data: %{ - "updateHardwareType" => %{ - "result" => nil, - "errors" => [error] - } - } + data: nil, + errors: [error] } = result error @@ -240,8 +229,7 @@ defmodule EdgehogWeb.Schema.Mutation.UpdateHardwareTypeTest do assert %{ data: %{ "updateHardwareType" => %{ - "result" => hardware_type, - "errors" => [] + "result" => hardware_type } } } = result