Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Hardware Type to Ash #433

Merged

Conversation

rbino
Copy link
Collaborator

@rbino rbino commented Jan 23, 2024

Add all the relevant tests in the Graphql part and remove unused old code

@rbino rbino changed the base branch from main to from-ash-we-rise January 23, 2024 16:31
@rbino rbino force-pushed the ash-hardware-type branch 4 times, most recently from 2dcb63f to 727dc6b Compare January 24, 2024 15:22
@rbino rbino force-pushed the ash-hardware-type branch 2 times, most recently from bbccaa7 to b9bfa39 Compare January 25, 2024 13:41
@rbino rbino marked this pull request as ready for review January 25, 2024 13:41
backend/lib/edgehog/devices/hardware_type.ex Outdated Show resolved Hide resolved
backend/lib/edgehog/devices/hardware_type.ex Outdated Show resolved Hide resolved
backend/lib/edgehog/devices/hardware_type.ex Outdated Show resolved Hide resolved
backend/lib/edgehog/devices/hardware_type.ex Show resolved Hide resolved

mutations do
create :create_hardware_type, :create
update :update_hardware_type, :update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  updateHardwareType(
    id: ID
    input: UpdateHardwareTypeInput
  ): UpdateHardwareTypeResult

Same here, ID and input should be non-nullable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

backend/lib/edgehog/devices/hardware_type.ex Show resolved Hide resolved
default_document = """
mutation DeleteHardwareType($id: ID!) {
deleteHardwareType(id: $id) {
result {
id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Querying partNumbers of deleted HardwareType (add next fields after id)

          partNumbers {
            partNumber
          }

returns null in result with

errors: [
    %{
      message: "Cannot return null for non-nullable field",
      path: ["deleteHardwareType", "result", "partNumbers", 0, "partNumber"],
      locations: [%{line: 6, column: 9}]
    }
  ]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, move to ash-porting issue


assert {:ok, %HardwareType{name: ^initial_name, handle: ^initial_handle}} =
Devices.fetch_hardware_type(hardware_type.id)
test "returns error for empty part_numbers", %{tenant: tenant, hardware_type: hardware_type} do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also check for invalid part_number like

    test "returns error for invalid part_number", %{tenant: tenant, hardware_type: hardware_type} do
      result =
        update_hardware_type_mutation(
          tenant: tenant,
          id: hardware_type.id,
          part_numbers: [""]
        )

      assert %{"fields" => ["part_number"], "message" => "is required"} =
               extract_error!(result)
    end

But we have no partNumber input field, not sure how to return this error better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, move to ash-porting issue


alias Edgehog.Devices.HardwareType
graphql do
type :hardware_type_part_number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type HardwareTypePartNumber {
  id: ID!

  "The part number identifier."
  partNumber: String!

  hardwareType: HardwareType
}

Should hardwareType field be non-nullable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked and currently hardware_type_id is actually nullable at the DB level (see here), so this is coherent with the status-quo.
The goal of the first step of the migration is having the resources reflect the current state of the database, then we can start adjusting the constraint with subsequent migrations.

name
handle
partNumbers {
partNumber
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having option to query hardwareType field on HardwareTypePartNumber type, do we want to test nested queries? like

          partNumbers {
            partNumber
            hardwareType {
              name
              handle
              partNumbers {
                partNumber
                hardwareType {
                  name
                  handle
                }
              }
            }
          }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll re-evaluate filters and sorts at the end of the porting process, please open a generic issue about this with the ash-porting label so that we have an item tracking this

This will be handled by AshGraphql now. Add a TODO to error.ex since it's not
possible to remove it now.

Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
Makes results nullable when using root level errors (see
ash-project/ash_graphql#114)

Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
Expose its queries and mutations via AshGraphql

Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
They map more naturally with the error handling we were currently using. We
could possibly evaluate reverting this in a second phase.

Signed-off-by: Riccardo Binetti <riccardo.binetti@secomind.com>
@szakhlypa szakhlypa merged commit 00f17db into edgehog-device-manager:from-ash-we-rise Feb 13, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants