Skip to content

Add ggt field {rename,remove} subcommands#2350

Merged
shardulbee merged 1 commit intomainfrom
push-knlwwuxnokol
Apr 2, 2026
Merged

Add ggt field {rename,remove} subcommands#2350
shardulbee merged 1 commit intomainfrom
push-knlwwuxnokol

Conversation

@shardulbee
Copy link
Copy Markdown
Contributor

Should be merged after https://github.com/gadget-inc/gadget/pull/20329 lands

Part of ggt shopify

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 31, 2026

🦋 Changeset detected

Latest commit: 695ecf2

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

Bugbot Autofix prepared fixes for all 3 issues found in the latest run.

  • ✅ Fixed: Wrong failure context for field mutations
    • Made AddClientError accept an operation parameter (defaulting to "add") and passed "remove field" / "rename field" from the respective subcommands.
  • ✅ Fixed: Missing model path passes field validation
    • Added a check in parseFieldTarget that returns a "Missing model identifier" problem when the model segment before the slash is empty.
  • ✅ Fixed: Colon input misparsed in field commands
    • Added fieldType presence checks in field remove and rename subcommands that reject colon-containing input with a clear error message.

Create PR

Or push these changes by commenting:

@cursor push 8787309d57
Preview (8787309d57)
diff --git a/src/commands/add.ts b/src/commands/add.ts
--- a/src/commands/add.ts
+++ b/src/commands/add.ts
@@ -21,8 +21,9 @@
 
 export class AddClientError extends GGTError {
   isBug = IsBug.NO;
+  operation: string;
 
-  constructor(error: ClientError) {
+  constructor(error: ClientError, operation = "add") {
     let template = "";
 
     if (isGraphQLErrors(error.cause)) {
@@ -38,11 +39,12 @@
     }
 
     super(template);
+    this.operation = operation;
   }
 
   protected override render(): string {
     return sprint`
-      ${colors.deleted(symbol.cross)} Failed to add:
+      ${colors.deleted(symbol.cross)} Failed to ${this.operation}:
        ${this.message}
     `;
   }

diff --git a/src/commands/field.ts b/src/commands/field.ts
--- a/src/commands/field.ts
+++ b/src/commands/field.ts
@@ -137,6 +137,9 @@
         if (parsed.problems.length > 0) {
           throw new FlagError(parsed.problems.join("\n"), { usageHint: false });
         }
+        if (parsed.fieldType) {
+          throw new FlagError("Field type is not allowed for remove. Use model/field format.", { usageHint: false });
+        }
 
         if (!flags["--force"]) {
           await confirm(`Remove ${parsed.fieldName} from ${parsed.modelApiIdentifier}?`);
@@ -152,7 +155,7 @@
           ).removeModelField;
         } catch (error) {
           if (error instanceof ClientError) {
-            throw new AddClientError(error);
+            throw new AddClientError(error, "remove field");
           }
           throw error;
         }
@@ -198,11 +201,17 @@
         if (source.problems.length > 0) {
           throw new FlagError(source.problems.join("\n"), { usageHint: false });
         }
+        if (source.fieldType) {
+          throw new FlagError("Field type is not allowed for rename. Use model/field format.", { usageHint: false });
+        }
 
         const target = parseFieldTarget(targetInput);
         if (target.problems.length > 0) {
           throw new FlagError(target.problems.join("\n"), { usageHint: false });
         }
+        if (target.fieldType) {
+          throw new FlagError("Field type is not allowed for rename. Use model/field format.", { usageHint: false });
+        }
 
         if (source.modelApiIdentifier !== target.modelApiIdentifier) {
           throw new FlagError(
@@ -225,7 +234,7 @@
           ).renameModelField;
         } catch (error) {
           if (error instanceof ClientError) {
-            throw new AddClientError(error);
+            throw new AddClientError(error, "rename field");
           }
           throw error;
         }

diff --git a/src/services/add/field.ts b/src/services/add/field.ts
--- a/src/services/add/field.ts
+++ b/src/services/add/field.ts
@@ -50,6 +50,10 @@
   const modelApiIdentifier = input.slice(0, lastSlashIndex);
   const fieldPart = input.slice(lastSlashIndex + 1);
 
+  if (!modelApiIdentifier) {
+    return { modelApiIdentifier: "", fieldName: "", fieldType: undefined, problems: ["Missing model identifier"] };
+  }
+
   // No colon means just a field name (e.g. "post/title" for remove/rename)
   if (!fieldPart.includes(":")) {
     return { modelApiIdentifier, fieldName: fieldPart, fieldType: undefined, problems: [] };

You can send follow-ups to this agent here.

@shardulbee shardulbee force-pushed the push-knlwwuxnokol branch 3 times, most recently from 894fa1c to ecfdc77 Compare April 1, 2026 15:00
@shardulbee shardulbee requested a review from scott-rc April 1, 2026 15:23
@shardulbee shardulbee merged commit 53b83ae into main Apr 2, 2026
13 checks passed
@shardulbee shardulbee deleted the push-knlwwuxnokol branch April 2, 2026 19:04
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.

2 participants