Skip to content

Conversation

@elibosley
Copy link
Member

@elibosley elibosley commented Apr 14, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new PrefixedID scalar type for all GraphQL IDs, ensuring unique identifiers across multiple servers by prefixing IDs with a server identifier.
    • Added detailed documentation for the PrefixedID scalar in the API schema.
    • Grouped VM and parity check mutations under dedicated fields for better organization.
    • Added new scalar Port and input type AccessUrlInput for improved type safety.
  • Refactor

    • Replaced all usages of standard ID or String with PrefixedID for IDs in queries, mutations, and models.
    • Consolidated ID handling by extending a common Node base class across models, removing redundant id declarations.
    • Updated GraphQL argument types and resolver signatures to explicitly use PrefixedID.
    • Updated GraphQL code generation to map PrefixedID to TypeScript string.
  • Bug Fixes

    • Enhanced test assertions to verify API key creation timestamps are strings.
    • Fixed internal property naming for registration ID.
  • Chores

    • Removed legacy ID prefix Apollo Server plugin in favor of the new scalar approach.
    • Cleaned up imports and unused fields related to ID handling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 14, 2025

Walkthrough

This update introduces a new custom GraphQL scalar, PrefixedID, replacing the standard ID type for all id fields in types implementing the Node interface and related input arguments. The change ensures that all IDs are prefixed with a server identifier for uniqueness across multiple servers. The update also removes redundant id field declarations by consolidating them into the Node base class, adjusts resolver and input argument types to use PrefixedID, and eliminates the now-unnecessary idPrefixPlugin. Additional minor changes include updating test expectations and refining import paths.

Changes

File(s) Change Summary
api/generated-schema.graphql Updated schema: replaced all ID! with PrefixedID! for Node types and arguments; added PrefixedID scalar with detailed description; reorganized VM and parity check mutations; added new enums and input types; updated mutation and query fields.
api/src/unraid-api/graph/scalars/graphql-type-prefixed-id.ts Introduced the PrefixedID custom scalar for GraphQL, implementing prefixing/stripping logic for IDs.
api/src/unraid-api/graph/graph.module.ts Updated scalar and plugin imports; registered PrefixedIDScalar; removed idPrefixPlugin.
api/src/unraid-api/graph/id-prefix-plugin.ts Deleted file; removed Apollo plugin for ID prefixing, replaced by scalar logic.
api/src/unraid-api/graph/resolvers/base.model.ts Changed id field in Node class from ID to PrefixedID; added string validation decorators.
api/src/unraid-api/graph/resolvers//.model.ts
api/src/unraid-api/graph/user/user.model.ts
Refactored all models implementing Node to extend the Node base class; removed explicit id field declarations; updated field types to use PrefixedID where necessary.
api/src/unraid-api/graph/resolvers//.resolver.ts
api/src/unraid-api/graph/resolvers/vms/vms.mutations.resolver.ts
Updated resolver argument decorators to use PrefixedID scalar for all relevant id arguments in queries and mutations.
api/src/unraid-api/graph/resolvers/api-key/api-key.model.ts ApiKey now extends Node; input types use PrefixedID for apiKeyId.
api/src/unraid-api/graph/resolvers/api-key/api-key.resolver.ts
api/src/unraid-api/graph/resolvers/disks/disks.resolver.ts
Updated resolver argument types for id to use PrefixedID.
api/src/unraid-api/graph/resolvers/array/array.model.ts Updated imports; refactored to extend Node; input types use PrefixedID for id.
api/src/unraid-api/graph/resolvers/array/array.mutations.resolver.ts Updated mutation argument types for id to use PrefixedID.
api/src/unraid-api/graph/resolvers/notifications/notifications.model.ts Refactored to extend Node; removed explicit id fields.
api/src/unraid-api/graph/resolvers/notifications/notifications.resolver.ts Updated all notification mutation arguments to use PrefixedID for IDs.
api/src/unraid-api/graph/resolvers/vms/vms.model.ts VmDomain now uses id: PrefixedID; Vms extends Node.
api/src/unraid-api/graph/resolvers/vms/vms.service.ts
api/src/unraid-api/graph/resolvers/vms/vms.service.spec.ts
Updated VM ID property usage from uuid to id in service and tests.
api/src/unraid-api/graph/resolvers/registration/registration.model.ts
api/src/unraid-api/graph/resolvers/registration/registration.resolver.ts
Registration now extends Node; property changed from guid to id.
api/src/unraid-api/graph/resolvers/flash/flash.model.ts
api/src/unraid-api/graph/resolvers/flash/flash.resolver.ts
Flash extends Node; removed explicit id field; updated returned property from guid to id.
api/src/unraid-api/graph/resolvers/docker/docker.model.ts
api/src/unraid-api/graph/resolvers/docker/docker.mutations.resolver.ts
Docker models now extend Node; updated mutation argument types for id to use PrefixedID.
api/src/unraid-api/graph/resolvers/connect/connect.model.ts
api/src/unraid-api/graph/resolvers/connect/connect-settings.resolver.ts
Refactored to extend Node; updated resolver return type for id to PrefixedID.
api/src/unraid-api/graph/services/service.model.ts Service now extends Node; removed explicit id field.
api/src/unraid-api/graph/resolvers/servers/server.model.ts ProfileModel and Server now extend Node; removed optional userId from ProfileModel.
api/src/unraid-api/auth/api-key.service.spec.ts Updated test assertions to expect createdAt as a string.
api/src/graphql/schema/utils.ts getLocalServer now sets id: 'local' for server and owner objects.
web/codegen.ts Added PrefixedID scalar mapping to TypeScript string in GraphQL codegen configuration.
web/components/Notifications/graphql/notification.query.ts Updated mutation input type for id from String! to PrefixedID!.
web/composables/gql/gql.ts Updated GraphQL operation signatures and overloads for mutations to use PrefixedID! instead of String! for id variables.
web/composables/gql/graphql.ts Replaced all ID scalar usages with PrefixedID; added Port scalar; added new enums and grouped mutations under VmMutations and ParityCheckMutations; added AccessUrlInput; removed deprecated mutations.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GraphQLServer
    participant PrefixedIDScalar
    participant Resolver/Service

    Client->>GraphQLServer: Query/Mutation with ID (may include prefix)
    GraphQLServer->>PrefixedIDScalar: parseValue(input ID)
    PrefixedIDScalar-->>GraphQLServer: ID stripped of prefix
    GraphQLServer->>Resolver/Service: Process request with raw ID
    Resolver/Service-->>GraphQLServer: Return data with raw ID
    GraphQLServer->>PrefixedIDScalar: serialize(raw ID)
    PrefixedIDScalar-->>GraphQLServer: ID with server prefix added
    GraphQLServer-->>Client: Response with prefixed ID
Loading

Possibly related PRs

Suggested reviewers

  • mdatelle
  • zackspear

Poem

IDs now wear a prefix hat,
Across the servers—imagine that!
The Node class reigns, less clutter in sight,
PrefixedID keeps collisions light.
Schema’s neat, the tests agree—
A tidy change for all to see!
🏷️✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@elibosley elibosley force-pushed the chore/server-prefix-scalar branch from 7661778 to 591f627 Compare April 14, 2025 20:31
@elibosley elibosley changed the title chore: update cache functionality to use nestjs-cache module chore: add a prefix scalar instead of prefix plugin Apr 14, 2025
Base automatically changed from feat/docker-container-caching-updates to main April 15, 2025 13:33
@elibosley elibosley requested a review from zackspear as a code owner April 15, 2025 13:33
@elibosley elibosley force-pushed the chore/server-prefix-scalar branch from 5df7b02 to 0a1d3b5 Compare April 15, 2025 13:39
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
api/src/unraid-api/graph/resolvers/connect/connect.model.ts (1)

1-1: Consider removing unnecessary ID import.

The import of ID from @nestjs/graphql is no longer needed since the classes now extend the Node base class, which provides the ID field implementation. It can be safely removed to clean up the imports.

-import { Field, ID, InputType, Int, ObjectType, registerEnumType } from '@nestjs/graphql';
+import { Field, InputType, Int, ObjectType, registerEnumType } from '@nestjs/graphql';
api/src/unraid-api/graph/resolvers/docker/docker.model.ts (1)

1-1: Consider removing unnecessary ID import.

The import of ID from @nestjs/graphql is no longer needed as the classes now extend the Node base class, which provides the ID field implementation.

-import { Field, ID, Int, ObjectType, registerEnumType } from '@nestjs/graphql';
+import { Field, Int, ObjectType, registerEnumType } from '@nestjs/graphql';
api/src/unraid-api/graph/scalars/graphql-type-prefixed-id.ts (2)

63-70: Consider cleaning up commented code

The commented-out code for prefix validation could be removed since it's not being used, or implemented if the validation is important.

 // Simple check to avoid double-prefixing if somehow already prefixed
 // This might happen if data is fetched internally already prefixed
 if (value.includes(':')) {
-    // Optionally log or verify if the prefix matches the current serverId
-    // const serverId = this.serverIdentifierService.getId();
-    // if (!value.startsWith(`${serverId}:`)) {
-    //     console.warn(`PrefixedID serialize: Value '${value}' already has a different prefix.`);
-    // }
     return value;
 }

87-88: Consider logging prefix warnings in production

The code suppresses a potentially helpful debug message when a value doesn't contain the expected prefix format. For debugging in production, consider enabling this log or adding it to a debug log system.

 // If it doesn't have the prefix format, assume it's an internal ID already.
-// console.debug(`PrefixedID parseValue: Value '${value}' does not contain expected prefix.`);
+console.debug(`PrefixedID parseValue: Value '${value}' does not contain expected prefix.`);
 return value;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea77de8 and 0a1d3b5.

📒 Files selected for processing (33)
  • api/generated-schema.graphql (39 hunks)
  • api/src/graphql/schema/utils.ts (1 hunks)
  • api/src/unraid-api/auth/api-key.service.spec.ts (1 hunks)
  • api/src/unraid-api/graph/graph.module.ts (3 hunks)
  • api/src/unraid-api/graph/id-prefix-plugin.ts (0 hunks)
  • api/src/unraid-api/graph/resolvers/api-key/api-key.model.ts (4 hunks)
  • api/src/unraid-api/graph/resolvers/api-key/api-key.resolver.ts (2 hunks)
  • api/src/unraid-api/graph/resolvers/array/array.model.ts (5 hunks)
  • api/src/unraid-api/graph/resolvers/array/array.mutations.resolver.ts (4 hunks)
  • api/src/unraid-api/graph/resolvers/base.model.ts (2 hunks)
  • api/src/unraid-api/graph/resolvers/config/config.model.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/connect/connect-settings.resolver.ts (2 hunks)
  • api/src/unraid-api/graph/resolvers/connect/connect.model.ts (4 hunks)
  • api/src/unraid-api/graph/resolvers/disks/disks.model.ts (2 hunks)
  • api/src/unraid-api/graph/resolvers/disks/disks.resolver.ts (2 hunks)
  • api/src/unraid-api/graph/resolvers/docker/docker.model.ts (3 hunks)
  • api/src/unraid-api/graph/resolvers/docker/docker.mutations.resolver.ts (3 hunks)
  • api/src/unraid-api/graph/resolvers/flash/flash.model.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/flash/flash.resolver.ts (0 hunks)
  • api/src/unraid-api/graph/resolvers/info/info.model.ts (16 hunks)
  • api/src/unraid-api/graph/resolvers/notifications/notifications.model.ts (3 hunks)
  • api/src/unraid-api/graph/resolvers/notifications/notifications.resolver.ts (4 hunks)
  • api/src/unraid-api/graph/resolvers/registration/registration.model.ts (2 hunks)
  • api/src/unraid-api/graph/resolvers/registration/registration.resolver.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/servers/server.model.ts (2 hunks)
  • api/src/unraid-api/graph/resolvers/vars/vars.model.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/vms/vms.model.ts (3 hunks)
  • api/src/unraid-api/graph/resolvers/vms/vms.mutations.resolver.ts (8 hunks)
  • api/src/unraid-api/graph/resolvers/vms/vms.service.spec.ts (2 hunks)
  • api/src/unraid-api/graph/resolvers/vms/vms.service.ts (1 hunks)
  • api/src/unraid-api/graph/scalars/graphql-type-prefixed-id.ts (1 hunks)
  • api/src/unraid-api/graph/services/service.model.ts (1 hunks)
  • api/src/unraid-api/graph/user/user.model.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • api/src/unraid-api/graph/resolvers/flash/flash.resolver.ts
  • api/src/unraid-api/graph/id-prefix-plugin.ts
🧰 Additional context used
🧬 Code Graph Analysis (8)
api/src/unraid-api/graph/resolvers/vars/vars.model.ts (1)
web/composables/gql/graphql.ts (1)
  • Node (932-934)
api/src/unraid-api/graph/resolvers/servers/server.model.ts (6)
api/src/unraid-api/graph/resolvers/registration/registration.model.ts (2)
  • ObjectType (79-86)
  • ObjectType (88-104)
api/src/unraid-api/graph/resolvers/array/array.model.ts (5)
  • ObjectType (9-19)
  • ObjectType (21-28)
  • ObjectType (30-128)
  • ObjectType (130-151)
  • ObjectType (239-287)
api/src/unraid-api/graph/resolvers/api-key/api-key.model.ts (3)
  • ObjectType (18-29)
  • ObjectType (31-58)
  • ObjectType (60-65)
api/src/unraid-api/graph/resolvers/config/config.model.ts (1)
  • ObjectType (5-14)
api/src/unraid-api/graph/resolvers/flash/flash.model.ts (1)
  • ObjectType (5-17)
web/composables/gql/graphql.ts (1)
  • Node (932-934)
api/src/unraid-api/graph/services/service.model.ts (1)
web/composables/gql/graphql.ts (1)
  • Node (932-934)
api/src/unraid-api/graph/resolvers/connect/connect.model.ts (1)
web/composables/gql/graphql.ts (4)
  • ConnectSettings (334-344)
  • Node (932-934)
  • Connect (324-332)
  • DynamicRemoteAccessStatus (590-598)
api/src/unraid-api/graph/resolvers/registration/registration.model.ts (1)
web/composables/gql/graphql.ts (2)
  • Node (932-934)
  • Registration (1128-1136)
api/src/unraid-api/graph/resolvers/notifications/notifications.model.ts (1)
web/composables/gql/graphql.ts (2)
  • Node (932-934)
  • Notifications (991-997)
api/src/unraid-api/graph/resolvers/array/array.model.ts (1)
web/composables/gql/graphql.ts (4)
  • ArrayDisk (102-145)
  • Node (932-934)
  • UnraidArray (1350-1369)
  • Share (1265-1298)
api/src/unraid-api/graph/scalars/graphql-type-prefixed-id.ts (1)
api/src/core/utils/server-identifier.ts (1)
  • getServerIdentifier (6-9)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build Web App
  • GitHub Check: Test API
  • GitHub Check: Build API
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (74)
api/src/unraid-api/graph/resolvers/vms/vms.service.spec.ts (3)

264-264: Update to validate id property existence

This change correctly verifies the existence of the new id property that replaced the previous uuid field, ensuring test compliance with the PrefixedID scalar implementation.


267-267: Updated VM start function to use id property

Properly updated to use testVm!.id instead of uuid when calling service.startVm(), maintaining consistency with the schema changes implementing the Node interface.


285-285: Updated VM stop function to use id property

Successfully switched from uuid to id when calling service.stopVm(), completing the implementation of the PrefixedID scalar pattern throughout VM operations.

api/src/unraid-api/graph/resolvers/registration/registration.resolver.ts (1)

36-36: Renamed property from guid to id

Changed the property name in the registration object from guid to id while retaining the same value source from emhttp.var.regGuid. This aligns with the Node interface implementation where entities use a standard id field with the PrefixedID scalar.

api/src/unraid-api/graph/resolvers/vms/vms.service.ts (1)

363-363: Property name changed from uuid to id

Updated the domain object mapping to use id instead of uuid as the property name, while still using the UUID string value. This properly aligns the service response with the GraphQL schema changes adopting the PrefixedID scalar.

api/src/graphql/schema/utils.ts (2)

86-86: Set explicit server ID

Added explicit 'local' identifier for the server object's id property, ensuring compatibility with the new PrefixedID scalar implementation that requires server identifiers for uniqueness across multiple servers.


88-88: Set explicit owner ID

Added explicit 'local' identifier for the owner object's id property, maintaining consistency with the server object and completing the migration to the PrefixedID scalar pattern.

api/src/unraid-api/graph/resolvers/vars/vars.model.ts (1)

35-35: Good refactoring to extend Node base class

The change from implementing the Node interface to extending the Node base class is a good approach. This eliminates the need for redundant id field declarations while maintaining the GraphQL interface implementation (through the @ObjectType decorator).

api/src/unraid-api/graph/resolvers/connect/connect-settings.resolver.ts (2)

27-27: Import of PrefixedID scalar

Good addition of the PrefixedID scalar import to replace the standard ID type.


35-35: Updated to use PrefixedID scalar

Correctly updated the return type from ID to PrefixedID, which aligns with the removal of the idPrefixPlugin in favor of the scalar approach.

api/src/unraid-api/auth/api-key.service.spec.ts (1)

523-523: More explicit test assertions

The test now properly specifies that createdAt should be a string type. This increases test precision and makes expectations clearer.

Also applies to: 529-530

api/src/unraid-api/graph/services/service.model.ts (1)

14-14: Good refactoring to extend Node base class

Similar to the Vars model, this change appropriately leverages inheritance from the Node base class while maintaining the GraphQL interface implementation through the decorator. This reduces code duplication and standardizes ID handling across models.

api/src/unraid-api/graph/resolvers/base.model.ts (2)

1-5: Good refactoring of imports to support the new PrefixedID scalar

The removal of the ID import and addition of PrefixedID along with validation decorators shows good attention to detail. This change forms the foundation for the entire migration.


47-50: Excellent addition of validation decorators

The validation decorators @IsString() and @IsNotEmpty() ensure that the id field is a non-empty string, which aligns perfectly with the expected behavior of the PrefixedID scalar. This helps prevent runtime errors by validating the data at the model level.

api/src/unraid-api/graph/resolvers/config/config.model.ts (2)

1-3: Clean import refactoring

Removal of the ID import and reliance on the Node class import simplifies the code.


8-8: Good use of inheritance

Changing from implements to extends is a solid refactoring that reduces code duplication by inheriting the id field with its new PrefixedID type and validation decorators.

api/src/unraid-api/graph/resolvers/flash/flash.model.ts (2)

1-3: Clean import refactoring

Removal of the ID import and reliance on the Node class import simplifies the code.


8-11:

❓ Verification inconclusive

Consider evaluating the relationship between id and guid

While the change to extend Node is good, note that Flash now has both an inherited id field and an explicit guid field. Consider whether there's redundancy between these fields or if they serve distinct purposes.


🏁 Script executed:

#!/bin/bash
# Find where Flash.guid is used in the codebase to understand its purpose
rg -A 3 "Flash.*guid" --type ts

Length of output: 33


Review Comment Revision: Evaluate the Relationship Between id and guid in Flash

The enhancement to extend Node is a positive change. However, since Flash now inherits an id field while also defining a guid field explicitly, it's unclear whether these fields serve distinct purposes or if there’s redundancy. An automated search for usages of Flash.guid did not return relevant results, which suggests that more manual investigation may be needed.

Please verify:

  • Whether the inherited id field (from Node) and the explicit guid are intentionally distinct—e.g., one might be used internally while the other is exposed externally.
  • That any unique identifier requirements for Flash are adequately met without unnecessary duplication.
  • The design and documentation of the base Node class to clarify what id represents compared to guid.
api/src/unraid-api/graph/graph.module.ts (3)

17-18: Clear import structure for scalars

The updated import path for GraphQLLong and the addition of PrefixedID ensure all scalars are consistently imported from the scalars directory.


44-44: Simplified plugin configuration

Removing the idPrefixPlugin is consistent with moving to a scalar-based approach for ID prefixing.


65-65: Proper scalar registration

Adding PrefixedIDScalar to the providers array ensures it's available throughout the application.

api/src/unraid-api/graph/resolvers/api-key/api-key.resolver.ts (2)

19-19: New import for PrefixedID scalar added correctly

The import for the custom PrefixedID scalar has been added properly, which will be used to replace the standard ID scalar.


44-47: Correctly updated id argument type to PrefixedID

The id argument in the apiKey resolver has been properly updated to use the custom PrefixedID scalar type. This is in line with the overall change to replace the id prefix plugin with a scalar-based approach.

api/src/unraid-api/graph/resolvers/registration/registration.model.ts (2)

1-3: Import updates align with Node inheritance pattern

Removed the ID import from @nestjs/graphql and added the Node import from base.model, which is appropriate given that Registration now extends Node.


88-89: Registration class now properly extends Node

The Registration class has been updated to extend the Node base class and implement the Node interface. This change standardizes the ID handling across entities and removes the need for explicit id field declarations.

api/src/unraid-api/graph/resolvers/disks/disks.resolver.ts (2)

11-11: Added PrefixedID scalar import

The import for the custom PrefixedID scalar has been properly added to support the updated argument type in the resolver method.


33-33: Disk resolver now uses PrefixedID scalar for id argument

The id argument in the disk query resolver has been correctly updated to use the PrefixedID scalar, which ensures consistent ID handling throughout the API.

api/src/unraid-api/graph/resolvers/servers/server.model.ts (3)

3-3: Added Node import to support inheritance

The import for Node from base.model.js has been added correctly to support the class inheritance changes.


5-6: ProfileModel now extends Node

ProfileModel has been updated to implement the Node interface and extend the Node base class, ensuring consistent ID handling.


27-28: Server class now extends Node

The Server class has been updated to implement the Node interface and extend the Node base class, aligning with the standardized approach to ID handling across the application.

api/src/unraid-api/graph/resolvers/docker/docker.mutations.resolver.ts (1)

27-28: LGTM: Types properly updated to use PrefixedID

The mutation arguments now correctly use the PrefixedID scalar type while maintaining string as the TypeScript type.

Also applies to: 37-38

api/src/unraid-api/graph/user/user.model.ts (1)

6-7: LGTM: Properly extends and implements Node

The UserAccount class correctly extends the Node base class while also implementing the Node interface, which aligns with the pattern of consolidating id fields in the base class.

api/src/unraid-api/graph/resolvers/api-key/api-key.model.ts (1)

116-118: LGTM: Input fields properly updated to PrefixedID

The apiKeyId fields in the input types correctly use the PrefixedID scalar.

Also applies to: 127-129

api/src/unraid-api/graph/resolvers/connect/connect.model.ts (4)

20-20: Good job adding the PrefixedID import.

The import of the custom scalar is necessary to support the change to server-prefixed IDs.


330-342: Good refactoring to extend Node base class.

Changing from implementing the Node interface to extending the Node base class promotes code reuse and reduces duplication. This approach centralizes the ID field implementation in one place.


347-356: Well-structured inheritance from Node base class.

The Connect class now properly extends Node while maintaining all its specific fields.


361-364: Consistent application of the Node base class.

The Network class has been updated to follow the same pattern as other classes, maintaining consistency across the codebase.

api/src/unraid-api/graph/resolvers/docker/docker.model.ts (3)

74-75: Good refactoring to extend the Node base class.

Changing DockerContainer to extend the Node base class while still implementing the Node interface through the decorator is a good approach that promotes code reuse and maintains type safety.


119-120: Consistent application of the Node base class pattern.

The DockerNetwork class follows the same pattern, ensuring consistency across the codebase.


167-167: Well-structured inheritance from Node.

The Docker class properly extends the Node base class, aligning with the broader refactoring in the codebase.

api/src/unraid-api/graph/resolvers/notifications/notifications.model.ts (3)

1-6: Clean import adjustments.

Good job removing the unused ID import and adding the Node import. This keeps the imports concise and relevant to what's actually used in the file.


114-117: Well-structured refactoring and cleanup.

Excellent work on both extending the Node base class and removing the duplicate @field decorator for the title property. This improves code cleanliness and follows the project's architectural patterns.


158-159: Consistent application of Node inheritance.

The Notifications class now properly extends Node and implements the Node interface, maintaining consistency with other model classes in the codebase.

api/src/unraid-api/graph/resolvers/notifications/notifications.resolver.ts (6)

21-21: Appropriate import of PrefixedID scalar.

Adding the import for the custom scalar type is necessary to support the argument type changes in the resolver methods.


70-71: Good scalar type update for ID argument.

Changing from String to PrefixedID scalar ensures IDs are properly prefixed with server identifiers. Note that the parameter type in the function signature is still string, which is correct since the scalar conversion happens at the GraphQL layer.


88-90: Consistent scalar usage for ID argument.

Using PrefixedID scalar consistently across all ID-related arguments maintains a uniform approach to ID handling.


96-98: Proper handling of ID array type.

Correctly updated the array of IDs to use the PrefixedID scalar. This ensures consistent handling of ID collections.


114-116: Consistent scalar usage for ID argument.

Using PrefixedID scalar for the unreadNotification method maintains consistency with other mutation methods.


122-124: Proper handling of ID array type.

Correctly updated the array of IDs to use the PrefixedID scalar in the unarchiveNotifications method.

api/src/unraid-api/graph/resolvers/vms/vms.model.ts (3)

1-6: Proper imports for the new Node and PrefixedID approach.

The imports correctly bring in the necessary dependencies for implementing the Node interface and using the new PrefixedID scalar type, along with class-validator decorators for input validation.


25-30: Good implementation of Node interface with proper validation.

The VmDomain class now correctly implements the Node interface, and the id field is properly typed with PrefixedID. The addition of validation decorators (@IsString and @isnotempty) ensures that the ID will always be properly validated.


39-40: Appropriate extension of Node base class.

The Vms class now properly extends the Node base class, eliminating redundant id field declaration and ensuring consistent ID handling.

api/src/unraid-api/graph/resolvers/array/array.mutations.resolver.ts (4)

18-18: Correctly importing the PrefixedID scalar.

The PrefixedID import is appropriately added to support the scalar usage in resolver arguments.


66-66: Properly typed id parameter in mountArrayDisk.

The id parameter is now correctly typed with PrefixedID, ensuring consistent ID handling across the API.


86-88: Properly typed id parameter in unmountArrayDisk.

The id parameter is now correctly typed with PrefixedID, maintaining type consistency throughout the API.


108-110: Properly typed id parameter in clearArrayDiskStatistics.

The id parameter is now correctly typed with PrefixedID, completing the consistent ID handling across all array-related operations.

api/src/unraid-api/graph/resolvers/info/info.model.ts (3)

14-14: Correctly importing the PrefixedID scalar.

The PrefixedID import is appropriately added to support the new scalar usage in the info models.


35-36: Consistent implementation of Node pattern across multiple classes.

All these information-related model classes now properly implement the Node interface and extend the Node base class, which eliminates redundant id field declarations and ensures consistent ID handling throughout the API. This refactoring significantly reduces code duplication.

Also applies to: 44-45, 62-63, 116-117, 137-138, 176-177, 203-204, 209-210, 221-222, 236-237, 299-300, 335-336, 371-372, 410-411, 431-432, 512-513


529-529: Updated machineId field to use PrefixedID scalar.

The machineId field type has been correctly updated from ID to PrefixedID to maintain consistency with the new approach to ID handling.

api/src/unraid-api/graph/resolvers/array/array.model.ts (5)

6-7: Updated imports for GraphQLLong and added PrefixedID.

The import for GraphQLLong has been updated to use the new path, and PrefixedID has been properly added for use in the array models.


33-33: ArrayDisk now extends Node base class.

ArrayDisk class now properly extends the Node base class, eliminating the need for a redundant id field declaration.


133-133: UnraidArray now extends Node base class.

UnraidArray class now properly extends the Node base class, maintaining consistency with the new pattern.


155-155: Updated id field in ArrayDiskInput to use PrefixedID.

The id field in the ArrayDiskInput class is now correctly typed with PrefixedID, ensuring type consistency between inputs and models.


242-242: Share now extends Node base class.

Share class now properly extends the Node base class, completing the consistent implementation across all array-related models.

api/src/unraid-api/graph/scalars/graphql-type-prefixed-id.ts (1)

1-107: Well-implemented custom scalar for ID prefixing

The PrefixedID scalar is a good approach to handling server-specific ID prefixing. The implementation properly handles both input (stripping prefix when present) and output (always adding prefix) scenarios.

A few observations:

  • Good detailed documentation on functionality in the description
  • Appropriate error handling for non-string values
  • Clean implementation of the required scalar methods
api/src/unraid-api/graph/resolvers/vms/vms.mutations.resolver.ts (2)

11-11: Import of new PrefixedID scalar

Correctly added import for the new PrefixedID scalar type.


26-26: Consistent type annotations for ID arguments

The resolver methods have been updated consistently to use the PrefixedID scalar type for all ID arguments, ensuring proper handling of server-prefixed IDs throughout the VM mutation operations.

Also applies to: 36-36, 46-46, 56-56, 66-66, 76-76, 86-86

api/generated-schema.graphql (7)

77-77: Consistent type changes across Node implementations

All types implementing the Node interface have been updated to use PrefixedID instead of ID, ensuring consistent handling of server-prefixed IDs throughout the schema.

Also applies to: 145-145, 183-183, 219-219, 350-350, 368-368, 378-378, 382-384, 389-391


826-832: Updated array mutation arguments to use PrefixedID

Array-related mutation arguments have been properly updated to use the PrefixedID scalar.


855-859: Updated Docker mutation arguments to use PrefixedID

Docker-related mutation arguments have been properly updated to use the PrefixedID scalar.


863-882: Updated VM mutation arguments to use PrefixedID

VM-related mutation arguments have been properly updated to use the PrefixedID scalar.


1390-1391: Addition of PrefixedID scalar to schema

The PrefixedID scalar has been properly defined with comprehensive documentation explaining its behavior for both input and output operations.


1484-1484: Updated API key input types to use PrefixedID

Input types for API key operations have been properly updated to use the PrefixedID scalar.

Also applies to: 1489-1489


1234-1236:

❓ Verification inconclusive

Changed useCache to skipCache with inverted default

The Docker type's container and network query fields have been updated to use skipCache with a default of false instead of useCache with a default of true. This change inverts the logic, so ensure any client code is updated accordingly.

Verify that client code has been updated to handle this change:


🏁 Script executed:

#!/bin/bash
# Search for any client code using the old useCache parameter
rg -A 2 -B 2 "useCache.*Docker" --glob "*.{ts,js,tsx,jsx}"

Length of output: 60


Client Code Verification Required: Confirm skipCache Update in Docker Fields

The GraphQL Docker type now uses skipCache with a default of false (inverting the previous logic from useCache with default true) for both containers and networks. The initial search for client references to the old useCache parameter returned no matches. However, please manually verify that all client code has updated accordingly.

  • Modified file: api/generated-schema.graphql (Lines: 1234-1236)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
web/composables/gql/graphql.ts (2)

25-26: Consider validating port range
Introducing the Port scalar enhances type safety for port numbers. If possible, add server-side validation to reject out-of-range or privileged ports (below 1024) if your use case disallows them.


312-317: New AuthActionVerb enum
This addition clarifies the allowed CRUD actions in your auth system. If relevant, consider including additional verbs like LIST or EXECUTE.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between a8e10c2 and 3080c63.

📒 Files selected for processing (4)
  • web/codegen.ts (1 hunks)
  • web/components/Notifications/graphql/notification.query.ts (2 hunks)
  • web/composables/gql/gql.ts (3 hunks)
  • web/composables/gql/graphql.ts (53 hunks)
✅ Files skipped from review due to trivial changes (2)
  • web/codegen.ts
  • web/composables/gql/gql.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (32)
web/components/Notifications/graphql/notification.query.ts (2)

38-38: Prefixed ID mutation argument
Changing the mutation argument from a generic ID or string to PrefixedID! is consistent with the new globally unique ID approach. Ensure all calls that pass the id variable are updated accordingly.


62-62: Confirm external references for the new scalar
Using PrefixedID! for deleteNotification aligns with the refactor. Double-check that related client code and any test cases now supply the new scalar format to avoid runtime errors.

web/composables/gql/graphql.ts (30)

27-74: Excellent documentation for PrefixedID
This thorough comment block clearly explains how the prefix is handled on input and output. Good job ensuring it's self-explanatory for future maintainers.


87-93: Typed URL fields
Switching from simple strings to URL scalars (for ipv4 and ipv6) provides better clarity and stricter type checks. This helps catch invalid URLs earlier.


100-100: Consistent use of PrefixedID
Ensuring apiKeyId is a PrefixedID aligns with the global ID scheme. Just confirm call sites pass the prefixed form to prevent mismatches.


109-113: ApiKey type update
Moving id to Scalars['PrefixedID']['output'] is consistent with the Node interface changes. This helps maintain a uniform ID strategy across the codebase.


125-129: ApiKeyWithSecret ID correction
Refactoring id to PrefixedID is a good continuation of the unified ID approach. No issues noted here.


178-178: ArrayDisk ID
The disk's id field now uses PrefixedID. This is consistent with the broader refactor.


217-217: ArrayDiskInput ID
Updating the field to PrefixedID['input'] keeps the schema consistent. Make sure any user inputs match the prefixed format.


264-264: ClearArrayDiskStatisticsArg update
Switching id to PrefixedID for clearing disk statistics maintains the standard ID approach.


269-269: MountArrayDiskArgs ID
Ensuring id is PrefixedID['input'] helps unify how array disk operations handle IDs.


284-284: UnmountArrayDiskArgs ID
Again, consistent with the overall PrefixedID refactor for disk-related mutations.


319-324: New AuthPossession enum
Defining ANY, OWN, and OWN_ANY clarifies resource ownership constraints. This is a useful approach to handle role-based access.


329-329: Baseboard ID
Swapping to PrefixedID ensures this node’s identifier is uniform with others.


351-351: Case ID
Refactored id field also adheres to the new prefix logic.


375-375: Config ID
Good move, no issues. Matches the node-based ID scheme.


392-392: Connect ID
Continued consistency for the Connect node.


454-455: Use of the Port scalar
Applying Port for privatePort and publicPort ensures type safety around container ports. Confirm server-side checks to guarantee valid port mappings.


495-495: Disk ID
No concerns; follows the PrefixedID standard.


611-611: DockerContainer ID
Leveraging the new scalar here is a positive step for consistent container identification.


635-635: DockerMutationsStartArgs
Using PrefixedID for starting a container is aligned with the unifying ID approach.


640-640: DockerMutationsStopArgs
Similarly consistent with the new ID approach here as well.


652-652: DockerNetwork ID
No issues; matches the existing pattern.


697-697: Gpu ID
Maintaining the same PrefixedID pattern.


712-712: Info ID
Adopting the new scalar type for the system info node.


714-714: machineId set to PrefixedID
Enabling machine-level prefixing for the internal machine ID fosters consistent referencing.


739-739: InfoCpu ID
Transitioning the CPU info ID to PrefixedID is in line with the rest.


759-759: InfoMemory ID
Follows the same prefixed pattern to unify memory info references.


799-804: MemoryLayout refactor
Declaring id as PrefixedID consolidates the node-based architecture.


682-682: EnableDynamicRemoteAccessInput
Replacing a simpler scalar with AccessUrlInput for the url field makes the incoming data more structured and explicit.


688-688: Flash ID
Keeping flash device identifiers aligned with the new scalar.


1684-1688: Vms type changes
Adding domain?: Maybe<Array<VmDomain>> and switching id to PrefixedID unify the VM schema with the rest of the codebase.

@elibosley elibosley force-pushed the chore/server-prefix-scalar branch from 3080c63 to 3fd7a71 Compare April 28, 2025 20:02
@github-actions
Copy link
Contributor

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL:

https://preview.dl.unraid.net/unraid-api/tag/PR1361/dynamix.unraid.net.plg

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
web/composables/gql/graphql.ts (3)

87-92: AccessUrlInput lacks URL validation

ipv4 / ipv6 are typed as URL, but nothing prevents a caller from sending ftp://…, javascript:…, or even '' (empty string).
If the server relies on these being HTTP(S) you should:

-  ipv4?: InputMaybe<Scalars['URL']['input']>;
+  /** Must start with http:// or https:// */
+  ipv4?: InputMaybe<Scalars['URL']['input']>;

…and mirror that rule in both the server scalar and front-end helpers.


1067-1085: Return JSON → define a real type

ParityCheckMutations.* all return JSON. This removes type-safety and forces callers to cast. Unless the shape is genuinely unstable, declare a dedicated payload, e.g.

type ParityCheckResult {
  ok: Boolean!
  message: String
  errors: [String!]
}

and swap the fields to that. It costs almost nothing and pays dividends in autocompletion.


1641-1657: VM mutation grouping is great – small DX polish

Nice consolidation under vm. Two low-effort ergonomics wins:

  1. Add a union return type (VmActionResult), mirroring the parity-check comment above.
  2. Consider a single action(id:, verb:) mutation instead of eight nearly identical fields; fewer documents & codegen artifacts.

Not blocking, but worth a think.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between c2f66de and bbc9ef5.

📒 Files selected for processing (2)
  • api/generated-schema.graphql (39 hunks)
  • web/composables/gql/graphql.ts (52 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/generated-schema.graphql
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build and Deploy Plugin / Build and Deploy Plugin
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (1)
web/composables/gql/graphql.ts (1)

949-952: Be prepared for widespread id type changes

Every Node now exposes PrefixedID. Generated documents were updated, but any handwritten GraphQL strings (tests, curl snippets, monitoring dashboards) will break if they still pass a bare ID.

Action items
• grep the repo for "$id" or id: ID to catch stragglers.
• run E2E tests with a mixed-server environment to ensure prefix handling works.

@elibosley elibosley merged commit 586653c into main Apr 29, 2025
9 checks passed
@elibosley elibosley deleted the chore/server-prefix-scalar branch April 29, 2025 16:22
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