Skip to content

Commit ccab2cb

Browse files
committed
Fix all GraphQL queries to match Inngest Cloud API schema
1 parent ea170cf commit ccab2cb

23 files changed

Lines changed: 1527 additions & 1937 deletions

internal/cli/commands/env.go

Lines changed: 59 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package commands
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
7+
"os"
68
"strings"
79

810
"github.com/spf13/cobra"
@@ -16,7 +18,7 @@ import (
1618
func NewEnvCmd() *cobra.Command {
1719
cmd := &cobra.Command{
1820
Use: "env",
19-
Short: "Manage environments (apps/deployments)",
21+
Short: "Manage environments (workspaces)",
2022
Long: "List, inspect, and switch between Inngest environments.",
2123
RunE: func(cmd *cobra.Command, args []string) error {
2224
return cmd.Help()
@@ -30,63 +32,54 @@ func NewEnvCmd() *cobra.Command {
3032

3133
// envRow is used for table output of env list.
3234
type envRow struct {
33-
Name string
34-
SDK string
35-
Framework string
36-
URL string
37-
Connected string
38-
Functions int
39-
Active string
35+
Name string
36+
Slug string
37+
Type string
38+
ID string
39+
Active string
4040
}
4141

4242
func newEnvListCmd() *cobra.Command {
4343
return &cobra.Command{
4444
Use: "list",
45-
Short: "List all environments (apps)",
46-
Long: "List all apps registered with Inngest Cloud or the local dev server.",
45+
Short: "List all environments",
46+
Long: "List all environments registered with Inngest Cloud.",
4747
RunE: func(cmd *cobra.Command, args []string) error {
4848
client := newCloudClient()
4949
format := output.Format(state.Output)
5050
ctx := context.Background()
5151

52-
apps, err := client.ListApps(ctx)
52+
envs, err := client.ListEnvironments(ctx)
5353
if err != nil {
54+
if errors.Is(err, inngest.ErrAccountAuthRequired) {
55+
return printCurrentEnvFallback(format, err)
56+
}
5457
return fmt.Errorf("listing environments: %w", err)
5558
}
5659

5760
if format == output.FormatTable {
58-
return printEnvTable(apps)
61+
return printEnvTable(envs)
5962
}
6063

61-
return output.Print(apps, format)
64+
return output.Print(envs, format)
6265
},
6366
}
6467
}
6568

66-
func printEnvTable(apps []inngest.App) error {
69+
func printEnvTable(envs []inngest.Environment) error {
6770
activeEnv := state.Env
68-
rows := make([]envRow, len(apps))
69-
for i, app := range apps {
70-
sdk := app.SDKLanguage
71-
if app.SDKVersion != "" {
72-
sdk += "/" + app.SDKVersion
73-
}
74-
connected := "no"
75-
if app.Connected {
76-
connected = "yes"
77-
}
71+
rows := make([]envRow, len(envs))
72+
for i, env := range envs {
7873
active := ""
79-
if strings.EqualFold(app.Name, activeEnv) {
74+
if strings.EqualFold(env.Name, activeEnv) || strings.EqualFold(env.Slug, activeEnv) {
8075
active = "◀"
8176
}
8277
rows[i] = envRow{
83-
Name: app.Name,
84-
SDK: sdk,
85-
Framework: app.Framework,
86-
URL: app.URL,
87-
Connected: connected,
88-
Functions: app.FunctionCount,
89-
Active: active,
78+
Name: env.Name,
79+
Slug: env.Slug,
80+
Type: env.Type,
81+
ID: env.ID,
82+
Active: active,
9083
}
9184
}
9285
return output.Print(rows, output.FormatTable)
@@ -117,84 +110,59 @@ func newEnvUseCmd() *cobra.Command {
117110
func newEnvGetCmd() *cobra.Command {
118111
return &cobra.Command{
119112
Use: "get <name-or-id>",
120-
Short: "Get detailed environment (app) info",
121-
Long: "Fetch full environment details including connected status and all functions.",
113+
Short: "Get environment details",
114+
Long: "Fetch environment details by name, slug, or ID.",
122115
Args: cobra.ExactArgs(1),
123116
RunE: func(cmd *cobra.Command, args []string) error {
124117
client := newCloudClient()
125118
format := output.Format(state.Output)
126119
ctx := context.Background()
127120
nameOrID := args[0]
128121

129-
// Try to find by name first by listing all apps.
130-
apps, err := client.ListApps(ctx)
122+
env, err := client.GetEnvironment(ctx, nameOrID)
131123
if err != nil {
132-
return fmt.Errorf("listing environments: %w", err)
133-
}
134-
135-
var app *inngest.App
136-
for i := range apps {
137-
if strings.EqualFold(apps[i].Name, nameOrID) || apps[i].ID == nameOrID {
138-
app = &apps[i]
139-
break
140-
}
141-
}
142-
143-
// If not found by name, try by ID via GetApp.
144-
if app == nil {
145-
app, err = client.GetApp(ctx, nameOrID)
146-
if err != nil {
147-
return fmt.Errorf("environment %q not found", nameOrID)
148-
}
149-
} else {
150-
// Fetch full details with functions/triggers via GetApp.
151-
detailed, err := client.GetApp(ctx, app.ID)
152-
if err == nil {
153-
app = detailed
124+
if errors.Is(err, inngest.ErrAccountAuthRequired) {
125+
return printCurrentEnvFallback(format, err)
154126
}
127+
return fmt.Errorf("environment %q not found: %w", nameOrID, err)
155128
}
156129

157130
if format == output.FormatText {
158-
return printEnvDetail(app)
131+
return printEnvDetail(env)
159132
}
160133

161-
return output.Print(app, format)
134+
return output.Print(env, format)
162135
},
163136
}
164137
}
165138

166-
func printEnvDetail(app *inngest.App) error {
167-
fmt.Printf("Name: %s\n", app.Name)
168-
fmt.Printf("ID: %s\n", app.ID)
169-
fmt.Printf("External ID: %s\n", app.ExternalID)
170-
fmt.Printf("SDK: %s/%s\n", app.SDKLanguage, app.SDKVersion)
171-
if app.Framework != "" {
172-
fmt.Printf("Framework: %s\n", app.Framework)
173-
}
174-
if app.URL != "" {
175-
fmt.Printf("URL: %s\n", app.URL)
176-
}
177-
if app.Method != "" {
178-
fmt.Printf("Method: %s\n", app.Method)
179-
}
180-
fmt.Printf("Connected: %v\n", app.Connected)
181-
fmt.Printf("Functions: %d\n", app.FunctionCount)
182-
if app.Checksum != "" {
183-
fmt.Printf("Checksum: %s\n", app.Checksum)
184-
}
185-
if app.Error != "" {
186-
fmt.Printf("Error: %s\n", app.Error)
139+
func printEnvDetail(env *inngest.Environment) error {
140+
fmt.Printf("Name: %s\n", env.Name)
141+
fmt.Printf("ID: %s\n", env.ID)
142+
fmt.Printf("Slug: %s\n", env.Slug)
143+
fmt.Printf("Type: %s\n", env.Type)
144+
if env.CreatedAt != nil {
145+
fmt.Printf("Created: %s\n", env.CreatedAt.Format("2006-01-02 15:04:05"))
187146
}
147+
fmt.Printf("Auto-Archive: %v\n", env.IsAutoArchiveEnabled)
148+
return nil
149+
}
188150

189-
if len(app.Functions) > 0 {
190-
fmt.Printf("\nFunctions:\n")
191-
for _, fn := range app.Functions {
192-
fmt.Printf(" - %s (%s)\n", fn.Name, fn.Slug)
193-
for _, t := range fn.Triggers {
194-
fmt.Printf(" trigger: %s:%s\n", t.Type, t.Value)
195-
}
196-
}
151+
// printCurrentEnvFallback shows the current environment from config when the
152+
// API requires account-level auth that we don't have. It prints a warning to
153+
// stderr, then outputs the locally-known environment info to stdout.
154+
func printCurrentEnvFallback(format output.Format, authErr error) error {
155+
activeEnv := state.Config.GetActiveEnv()
156+
157+
// Print warning to stderr so structured output on stdout stays clean.
158+
fmt.Fprintln(os.Stderr, "Warning: "+authErr.Error())
159+
fmt.Fprintln(os.Stderr, "Showing current environment from local config instead.")
160+
fmt.Fprintln(os.Stderr)
161+
162+
info := map[string]string{
163+
"active_env": activeEnv,
164+
"source": "local_config",
165+
"hint": "Visit https://app.inngest.com/env to manage all environments",
197166
}
198-
199-
return nil
167+
return output.Print(info, format)
200168
}

0 commit comments

Comments
 (0)