@salesforce/graphiti 10.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENT_GUIDE.md +424 -0
- package/CHANGELOG.md +448 -0
- package/LICENSE.txt +82 -0
- package/README.md +204 -0
- package/TASK.md +249 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +683 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/args.d.ts +13 -0
- package/dist/commands/args.js +207 -0
- package/dist/commands/args.js.map +1 -0
- package/dist/commands/build.d.ts +11 -0
- package/dist/commands/build.js +209 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/connect.d.ts +8 -0
- package/dist/commands/connect.js +55 -0
- package/dist/commands/connect.js.map +1 -0
- package/dist/commands/describe.d.ts +6 -0
- package/dist/commands/describe.js +229 -0
- package/dist/commands/describe.js.map +1 -0
- package/dist/commands/meta.d.ts +9 -0
- package/dist/commands/meta.js +140 -0
- package/dist/commands/meta.js.map +1 -0
- package/dist/commands/navigate.d.ts +14 -0
- package/dist/commands/navigate.js +105 -0
- package/dist/commands/navigate.js.map +1 -0
- package/dist/commands/query-helpers.d.ts +80 -0
- package/dist/commands/query-helpers.js +865 -0
- package/dist/commands/query-helpers.js.map +1 -0
- package/dist/commands/query.d.ts +26 -0
- package/dist/commands/query.js +901 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/review.d.ts +18 -0
- package/dist/commands/review.js +533 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/commands/session-mgmt.d.ts +25 -0
- package/dist/commands/session-mgmt.js +206 -0
- package/dist/commands/session-mgmt.js.map +1 -0
- package/dist/commands/type.d.ts +6 -0
- package/dist/commands/type.js +342 -0
- package/dist/commands/type.js.map +1 -0
- package/dist/commands/validate-input.d.ts +6 -0
- package/dist/commands/validate-input.js +32 -0
- package/dist/commands/validate-input.js.map +1 -0
- package/dist/intent/build-aggregate.d.ts +33 -0
- package/dist/intent/build-aggregate.js +134 -0
- package/dist/intent/build-aggregate.js.map +1 -0
- package/dist/intent/build-create.d.ts +14 -0
- package/dist/intent/build-create.js +16 -0
- package/dist/intent/build-create.js.map +1 -0
- package/dist/intent/build-delete.d.ts +30 -0
- package/dist/intent/build-delete.js +53 -0
- package/dist/intent/build-delete.js.map +1 -0
- package/dist/intent/build-detail.d.ts +32 -0
- package/dist/intent/build-detail.js +80 -0
- package/dist/intent/build-detail.js.map +1 -0
- package/dist/intent/build-discover.d.ts +30 -0
- package/dist/intent/build-discover.js +149 -0
- package/dist/intent/build-discover.js.map +1 -0
- package/dist/intent/build-list.d.ts +28 -0
- package/dist/intent/build-list.js +75 -0
- package/dist/intent/build-list.js.map +1 -0
- package/dist/intent/build-mutation.d.ts +23 -0
- package/dist/intent/build-mutation.js +54 -0
- package/dist/intent/build-mutation.js.map +1 -0
- package/dist/intent/build-output.d.ts +27 -0
- package/dist/intent/build-output.js +60 -0
- package/dist/intent/build-output.js.map +1 -0
- package/dist/intent/build-raw.d.ts +23 -0
- package/dist/intent/build-raw.js +54 -0
- package/dist/intent/build-raw.js.map +1 -0
- package/dist/intent/build-update.d.ts +14 -0
- package/dist/intent/build-update.js +16 -0
- package/dist/intent/build-update.js.map +1 -0
- package/dist/intent/get-schema-with-priming.d.ts +26 -0
- package/dist/intent/get-schema-with-priming.js +32 -0
- package/dist/intent/get-schema-with-priming.js.map +1 -0
- package/dist/intent/select-child-relationship.d.ts +19 -0
- package/dist/intent/select-child-relationship.js +38 -0
- package/dist/intent/select-child-relationship.js.map +1 -0
- package/dist/intent/types.d.ts +159 -0
- package/dist/intent/types.js +21 -0
- package/dist/intent/types.js.map +1 -0
- package/dist/lib/apply-command.d.ts +15 -0
- package/dist/lib/apply-command.js +238 -0
- package/dist/lib/apply-command.js.map +1 -0
- package/dist/lib/auth.d.ts +38 -0
- package/dist/lib/auth.js +113 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/codegen.d.ts +32 -0
- package/dist/lib/codegen.js +700 -0
- package/dist/lib/codegen.js.map +1 -0
- package/dist/lib/command-registry.d.ts +59 -0
- package/dist/lib/command-registry.js +366 -0
- package/dist/lib/command-registry.js.map +1 -0
- package/dist/lib/formatter.d.ts +76 -0
- package/dist/lib/formatter.js +419 -0
- package/dist/lib/formatter.js.map +1 -0
- package/dist/lib/fs-utils.d.ts +23 -0
- package/dist/lib/fs-utils.js +46 -0
- package/dist/lib/fs-utils.js.map +1 -0
- package/dist/lib/graphql-name.d.ts +27 -0
- package/dist/lib/graphql-name.js +32 -0
- package/dist/lib/graphql-name.js.map +1 -0
- package/dist/lib/interactive.d.ts +6 -0
- package/dist/lib/interactive.js +562 -0
- package/dist/lib/interactive.js.map +1 -0
- package/dist/lib/introspect.d.ts +40 -0
- package/dist/lib/introspect.js +280 -0
- package/dist/lib/introspect.js.map +1 -0
- package/dist/lib/object-info.d.ts +79 -0
- package/dist/lib/object-info.js +313 -0
- package/dist/lib/object-info.js.map +1 -0
- package/dist/lib/path-selection.d.ts +50 -0
- package/dist/lib/path-selection.js +146 -0
- package/dist/lib/path-selection.js.map +1 -0
- package/dist/lib/prime-schema.d.ts +59 -0
- package/dist/lib/prime-schema.js +158 -0
- package/dist/lib/prime-schema.js.map +1 -0
- package/dist/lib/query-builder.d.ts +10 -0
- package/dist/lib/query-builder.js +168 -0
- package/dist/lib/query-builder.js.map +1 -0
- package/dist/lib/query-commands.d.ts +19 -0
- package/dist/lib/query-commands.js +262 -0
- package/dist/lib/query-commands.js.map +1 -0
- package/dist/lib/session.d.ts +205 -0
- package/dist/lib/session.js +1075 -0
- package/dist/lib/session.js.map +1 -0
- package/dist/lib/tokenize.d.ts +12 -0
- package/dist/lib/tokenize.js +48 -0
- package/dist/lib/tokenize.js.map +1 -0
- package/dist/lib/uiapi.d.ts +109 -0
- package/dist/lib/uiapi.js +159 -0
- package/dist/lib/uiapi.js.map +1 -0
- package/dist/lib/validator.d.ts +27 -0
- package/dist/lib/validator.js +100 -0
- package/dist/lib/validator.js.map +1 -0
- package/dist/lib/variable-promotion.d.ts +69 -0
- package/dist/lib/variable-promotion.js +95 -0
- package/dist/lib/variable-promotion.js.map +1 -0
- package/dist/lib/walker.d.ts +147 -0
- package/dist/lib/walker.js +723 -0
- package/dist/lib/walker.js.map +1 -0
- package/dist/mcp/server.d.ts +7 -0
- package/dist/mcp/server.js +34 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/stdio.d.ts +7 -0
- package/dist/mcp/stdio.js +25 -0
- package/dist/mcp/stdio.js.map +1 -0
- package/dist/mcp/tools/echo.d.ts +7 -0
- package/dist/mcp/tools/echo.js +17 -0
- package/dist/mcp/tools/echo.js.map +1 -0
- package/dist/mcp/tools/sf-gql-aggregate.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-aggregate.js +75 -0
- package/dist/mcp/tools/sf-gql-aggregate.js.map +1 -0
- package/dist/mcp/tools/sf-gql-create.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-create.js +35 -0
- package/dist/mcp/tools/sf-gql-create.js.map +1 -0
- package/dist/mcp/tools/sf-gql-delete.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-delete.js +31 -0
- package/dist/mcp/tools/sf-gql-delete.js.map +1 -0
- package/dist/mcp/tools/sf-gql-detail.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-detail.js +58 -0
- package/dist/mcp/tools/sf-gql-detail.js.map +1 -0
- package/dist/mcp/tools/sf-gql-discover.d.ts +9 -0
- package/dist/mcp/tools/sf-gql-discover.js +51 -0
- package/dist/mcp/tools/sf-gql-discover.js.map +1 -0
- package/dist/mcp/tools/sf-gql-list.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-list.js +53 -0
- package/dist/mcp/tools/sf-gql-list.js.map +1 -0
- package/dist/mcp/tools/sf-gql-raw.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-raw.js +39 -0
- package/dist/mcp/tools/sf-gql-raw.js.map +1 -0
- package/dist/mcp/tools/sf-gql-update.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-update.js +35 -0
- package/dist/mcp/tools/sf-gql-update.js.map +1 -0
- package/dist/mcp/tools/shared/zod-schemas.d.ts +49 -0
- package/dist/mcp/tools/shared/zod-schemas.js +46 -0
- package/dist/mcp/tools/shared/zod-schemas.js.map +1 -0
- package/package.json +36 -0
- package/ralph-loop.sh +120 -0
- package/scripts/smoke-orderby.sh +190 -0
- package/src/__tests__/helpers/prime-deps.ts +46 -0
- package/src/__tests__/helpers/schema.ts +73 -0
- package/src/__tests__/helpers/stdout.ts +33 -0
- package/src/__tests__/setup.ts +19 -0
- package/src/cli.ts +764 -0
- package/src/commands/__tests__/query.spec.ts +137 -0
- package/src/commands/args.ts +306 -0
- package/src/commands/build.ts +288 -0
- package/src/commands/connect.ts +60 -0
- package/src/commands/describe.ts +246 -0
- package/src/commands/meta.ts +171 -0
- package/src/commands/navigate.ts +134 -0
- package/src/commands/query-helpers.ts +1202 -0
- package/src/commands/query.ts +1085 -0
- package/src/commands/review.ts +670 -0
- package/src/commands/session-mgmt.ts +256 -0
- package/src/commands/type.ts +437 -0
- package/src/commands/validate-input.ts +38 -0
- package/src/intent/__tests__/build-aggregate.spec.ts +931 -0
- package/src/intent/__tests__/build-create-validation.spec.ts +135 -0
- package/src/intent/__tests__/build-delete.spec.ts +121 -0
- package/src/intent/__tests__/build-detail.spec.ts +333 -0
- package/src/intent/__tests__/build-discover.spec.ts +432 -0
- package/src/intent/__tests__/build-list.spec.ts +284 -0
- package/src/intent/__tests__/build-mutation.spec.ts +108 -0
- package/src/intent/__tests__/build-output.spec.ts +55 -0
- package/src/intent/__tests__/build-raw.spec.ts +153 -0
- package/src/intent/__tests__/build-update-validation.spec.ts +134 -0
- package/src/intent/build-aggregate.ts +182 -0
- package/src/intent/build-create.ts +19 -0
- package/src/intent/build-delete.ts +62 -0
- package/src/intent/build-detail.ts +95 -0
- package/src/intent/build-discover.ts +199 -0
- package/src/intent/build-list.ts +91 -0
- package/src/intent/build-mutation.ts +75 -0
- package/src/intent/build-output.ts +72 -0
- package/src/intent/build-raw.ts +61 -0
- package/src/intent/build-update.ts +19 -0
- package/src/intent/get-schema-with-priming.ts +43 -0
- package/src/intent/select-child-relationship.ts +48 -0
- package/src/intent/types.ts +181 -0
- package/src/lib/__tests__/apply-command.parity.spec.ts +97 -0
- package/src/lib/__tests__/apply-command.spec.ts +171 -0
- package/src/lib/__tests__/auth.spec.ts +292 -0
- package/src/lib/__tests__/formatter.spec.ts +86 -0
- package/src/lib/__tests__/graphql-name.spec.ts +64 -0
- package/src/lib/__tests__/introspect.spec.ts +399 -0
- package/src/lib/__tests__/object-info.spec.ts +124 -0
- package/src/lib/__tests__/path-selection.spec.ts +219 -0
- package/src/lib/__tests__/prime-schema.spec.ts +269 -0
- package/src/lib/__tests__/query-builder.spec.ts +95 -0
- package/src/lib/__tests__/query-commands.spec.ts +74 -0
- package/src/lib/__tests__/session.spec.ts +292 -0
- package/src/lib/__tests__/tokenize.spec.ts +33 -0
- package/src/lib/__tests__/uiapi.spec.ts +192 -0
- package/src/lib/__tests__/variable-promotion.spec.ts +211 -0
- package/src/lib/__tests__/walker.spec.ts +250 -0
- package/src/lib/apply-command.ts +286 -0
- package/src/lib/auth.ts +157 -0
- package/src/lib/codegen.ts +899 -0
- package/src/lib/command-registry.ts +434 -0
- package/src/lib/formatter.ts +587 -0
- package/src/lib/fs-utils.ts +46 -0
- package/src/lib/graphql-name.ts +35 -0
- package/src/lib/interactive.ts +634 -0
- package/src/lib/introspect.ts +320 -0
- package/src/lib/object-info.ts +409 -0
- package/src/lib/path-selection.ts +162 -0
- package/src/lib/prime-schema.ts +195 -0
- package/src/lib/query-builder.ts +193 -0
- package/src/lib/query-commands.ts +290 -0
- package/src/lib/session.ts +1304 -0
- package/src/lib/tokenize.ts +43 -0
- package/src/lib/uiapi.ts +176 -0
- package/src/lib/validator.ts +143 -0
- package/src/lib/variable-promotion.ts +145 -0
- package/src/lib/walker.ts +975 -0
- package/src/mcp/__tests__/server.spec.ts +155 -0
- package/src/mcp/server.ts +38 -0
- package/src/mcp/stdio.ts +29 -0
- package/src/mcp/tools/__tests__/sf-gql-aggregate.spec.ts +173 -0
- package/src/mcp/tools/__tests__/sf-gql-create.spec.ts +235 -0
- package/src/mcp/tools/__tests__/sf-gql-delete.spec.ts +194 -0
- package/src/mcp/tools/__tests__/sf-gql-detail.spec.ts +246 -0
- package/src/mcp/tools/__tests__/sf-gql-discover.spec.ts +320 -0
- package/src/mcp/tools/__tests__/sf-gql-list.spec.ts +128 -0
- package/src/mcp/tools/__tests__/sf-gql-raw.spec.ts +141 -0
- package/src/mcp/tools/__tests__/sf-gql-update.spec.ts +207 -0
- package/src/mcp/tools/echo.ts +24 -0
- package/src/mcp/tools/sf-gql-aggregate.ts +102 -0
- package/src/mcp/tools/sf-gql-create.ts +55 -0
- package/src/mcp/tools/sf-gql-delete.ts +49 -0
- package/src/mcp/tools/sf-gql-detail.ts +85 -0
- package/src/mcp/tools/sf-gql-discover.ts +67 -0
- package/src/mcp/tools/sf-gql-list.ts +73 -0
- package/src/mcp/tools/sf-gql-raw.ts +56 -0
- package/src/mcp/tools/sf-gql-update.ts +55 -0
- package/src/mcp/tools/shared/zod-schemas.ts +55 -0
- package/tsconfig.json +18 -0
- package/vitest.config.ts +14 -0
package/AGENT_GUIDE.md
ADDED
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
# Graphiti Agent Guide (v2)
|
|
2
|
+
|
|
3
|
+
Graphiti is a CLI for building and executing Salesforce GraphQL queries by navigating the schema like a filesystem. A **session** holds the current navigation path and query projection.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
graphiti agent-guide # print this guide (for agents)
|
|
9
|
+
graphiti connect <org> # download schema (one-time per org)
|
|
10
|
+
graphiti new <org> --name myQuery # create a session
|
|
11
|
+
graphiti use myQuery # set it as active (persists)
|
|
12
|
+
graphiti cd uiapi/query/Case/edges/node
|
|
13
|
+
graphiti select Id Subject.value:subject Status.value:status
|
|
14
|
+
graphiti set uiapi/query/Case first=10
|
|
15
|
+
graphiti check # validate
|
|
16
|
+
graphiti run # execute
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Session Resolution
|
|
20
|
+
|
|
21
|
+
All session commands target the **active session** implicitly. Resolution order:
|
|
22
|
+
|
|
23
|
+
1. `--session <id>` / `-s <id>` flag (highest priority)
|
|
24
|
+
2. `GRAPHITI_SESSION` env var
|
|
25
|
+
3. `~/.graphiti/active` file (set by `graphiti use`)
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
graphiti use myQuery # sets active session
|
|
29
|
+
graphiti select Id # targets myQuery implicitly
|
|
30
|
+
graphiti -s other select Id # targets "other" for this command only
|
|
31
|
+
GRAPHITI_SESSION=other graphiti ls # env var override
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## JSON / Agent Mode
|
|
35
|
+
|
|
36
|
+
Every command supports `--json` for structured JSON output. Set `GRAPHITI_AGENT=1` for all commands:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
graphiti show --json # single command JSON
|
|
40
|
+
GRAPHITI_AGENT=1 graphiti ls # all output is JSON
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Exit codes: 0=success, 1=user error, 2=validation failure, 3=execution failure, 4=auth failure.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Session Management
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
graphiti new <org> [--mutation] [--aggregate] [--name <n>] [--force]
|
|
51
|
+
graphiti use <session-id-or-name>
|
|
52
|
+
graphiti sessions # list all sessions
|
|
53
|
+
graphiti sessions rm <id-or-name> # delete a session
|
|
54
|
+
graphiti sessions prune --older-than 7d # prune old sessions
|
|
55
|
+
graphiti clone [name] # duplicate current session
|
|
56
|
+
graphiti reset # clear all state in current session
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Navigation
|
|
62
|
+
|
|
63
|
+
The schema is a tree rooted at `/`. Navigate with `cd`, inspect with `ls`.
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pwd # print current path
|
|
67
|
+
cd uiapi/query/Account # absolute path (query/ prefix auto-added)
|
|
68
|
+
cd edges/node # relative path
|
|
69
|
+
cd @args # enter arguments directory
|
|
70
|
+
cd @args/where # enter a specific argument
|
|
71
|
+
cd /variables # jump to variables
|
|
72
|
+
cd .. # go up one level
|
|
73
|
+
cd / # go to root
|
|
74
|
+
ls # list fields (20 by default)
|
|
75
|
+
ls -l # long listing with metadata (shows [required] on args)
|
|
76
|
+
ls -a # show all fields
|
|
77
|
+
ls --search Name # filter by name (CamelCase prefix match)
|
|
78
|
+
ls Name Owner Status # peek inside multiple directories
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Shell-safe fragment syntax
|
|
82
|
+
|
|
83
|
+
Union/interface types use `on:TypeName` instead of `[TypeName]` to avoid shell quoting:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
cd Owner/on:User
|
|
87
|
+
select Owner.on:User.Name.value:ownerName
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Building the Projection
|
|
93
|
+
|
|
94
|
+
Select leaf fields with **absolute or relative paths**. Dot-path syntax with inline aliases:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
select Id # plain leaf
|
|
98
|
+
select Name.value:name # dot-path with alias
|
|
99
|
+
select Id Subject.value:subject Status.value # multiple fields
|
|
100
|
+
select uiapi/query/Case/edges/node/Id # absolute path (no cd needed)
|
|
101
|
+
select ls # list all selected fields
|
|
102
|
+
drop <alias-or-path> # remove by alias or path
|
|
103
|
+
drop ownerName
|
|
104
|
+
drop $filter # remove a variable
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Agent best practice**: Use absolute paths to avoid interleaving `cd` with `select`:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
graphiti select \
|
|
111
|
+
uiapi/query/Case/edges/node/Id \
|
|
112
|
+
uiapi/query/Case/edges/node/Subject.value:subject \
|
|
113
|
+
uiapi/query/Case/edges/node/Status.value:status
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### @optional Directive (Field-Level Security)
|
|
117
|
+
|
|
118
|
+
Salesforce field-level security (FLS) can cause fields to be absent from the response at runtime. The `@optional` directive tells the API to return `null` instead of erroring when FLS blocks a field. **This should be the standard way to request fields** so FLS issues are handled gracefully.
|
|
119
|
+
|
|
120
|
+
Apply at selection time with `--optional`:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
select --optional Subject.value:subject Status.value:status
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Or toggle on already-selected fields:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
optional Subject Status # add @optional
|
|
130
|
+
optional --remove Subject # remove @optional
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The `@optional` directive appears in the rendered query:
|
|
134
|
+
|
|
135
|
+
```graphql
|
|
136
|
+
query {
|
|
137
|
+
uiapi {
|
|
138
|
+
query {
|
|
139
|
+
Case {
|
|
140
|
+
edges {
|
|
141
|
+
node {
|
|
142
|
+
Subject @optional {
|
|
143
|
+
value
|
|
144
|
+
}
|
|
145
|
+
Status @optional {
|
|
146
|
+
value
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
In `ls` output, fields with `@optional` are marked with `?`:
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
* Id
|
|
160
|
+
?*Subject/
|
|
161
|
+
?*Status/
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
In `select ls`, `@optional` fields are tagged:
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
Subject.value → subject @optional
|
|
168
|
+
Status.value → status @optional
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
In `codegen` output, `@optional` fields become optional TypeScript properties with `| undefined`:
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
Subject?: { value: string | null } | null | undefined;
|
|
175
|
+
Status?: { value: CaseStatus | null } | null | undefined;
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Arguments (set / unset)
|
|
181
|
+
|
|
182
|
+
Use **inline key=value syntax** for efficiency:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
set first=10 # set on current field
|
|
186
|
+
set uiapi/query/Case first=10 scope=MINE # with absolute field path
|
|
187
|
+
set where='{"Status":{"eq":"New"}}' # JSON value
|
|
188
|
+
set uiapi/query/Case/edges/node/CaseComments first=50 orderBy='[{"CreatedDate":{"order":"DESC"}}]'
|
|
189
|
+
unset first # remove an argument
|
|
190
|
+
unset where/Name/like # remove nested arg
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Legacy pair syntax still works:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
set @args/first 10
|
|
197
|
+
set @args/where/Name/like "Acme%"
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Pagination shorthand (`cursor`)
|
|
201
|
+
|
|
202
|
+
Add `cursor` to any `set` command to enable cursor-based pagination in one step:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
set uiapi/query/Case first=10 cursor
|
|
206
|
+
# Equivalent to:
|
|
207
|
+
# set uiapi/query/Case first=10
|
|
208
|
+
# var $after uiapi/query/Case/@args/after
|
|
209
|
+
# select uiapi/query/Case/pageInfo/hasNextPage uiapi/query/Case/pageInfo/endCursor
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
This defines `$after: String`, binds it to the connection's `after` arg, and auto-selects `pageInfo { hasNextPage endCursor }` so pagination loops work out of the box.
|
|
213
|
+
|
|
214
|
+
### ObjectInfo Guardrails
|
|
215
|
+
|
|
216
|
+
When setting arguments, the CLI warns immediately about:
|
|
217
|
+
|
|
218
|
+
- **Invalid picklist values**: `Warning: "Invalid" is not a known picklist value for Status. Valid values: New, On Hold, ...`
|
|
219
|
+
- **Non-filterable fields in where**: `Warning: Description is not filterable per ObjectInfo.`
|
|
220
|
+
- **Non-sortable fields in orderBy**: `Warning: Description is not sortable per ObjectInfo.`
|
|
221
|
+
- **Create-only fields in update mutations**: `Warning: ParentId is create-only (not updateable).`
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Variables (var)
|
|
226
|
+
|
|
227
|
+
Variables make arguments parameterisable:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
var $filter @args/where # auto-infer type and bind
|
|
231
|
+
var $limit @args/first 10 # with default value
|
|
232
|
+
var $caseId uiapi/query/Case/@args/where/Id/eq # bind to a deep arg path
|
|
233
|
+
set $filter '{"Name":{"like":"Acme%"}}' # set runtime value
|
|
234
|
+
run --var caseId=500SG00001KZliXYAT # ad-hoc override at execution
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Aliases (multiple queries in one request)
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
cd uiapi/query
|
|
243
|
+
alias newCases Case
|
|
244
|
+
set newCases/@args/where '{"Status":{"eq":"New"}}'
|
|
245
|
+
set newCases/@args/first 10
|
|
246
|
+
select newCases/edges/node/Id newCases/edges/node/Subject/value
|
|
247
|
+
|
|
248
|
+
alias myCases Case
|
|
249
|
+
set myCases/@args/scope MINE
|
|
250
|
+
set myCases/@args/first 20
|
|
251
|
+
select myCases/edges/node/Id myCases/edges/node/Status/value
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## Review & Execute
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
show # full session snapshot
|
|
260
|
+
show --json # JSON output (most important for agents)
|
|
261
|
+
check # validate against schema + Salesforce semantics
|
|
262
|
+
run # execute against the org
|
|
263
|
+
run --dry-run # preview without executing
|
|
264
|
+
run --var caseId=500xxx # ad-hoc variable override
|
|
265
|
+
describe Case # inspect SObject with ObjectInfo metadata
|
|
266
|
+
codegen # generate client types (default: TypeScript)
|
|
267
|
+
codegen --language typescript # explicit language selection
|
|
268
|
+
codegen -l ts --out types.ts --name CaseDetail
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Supported `--language` values: `typescript` (alias `ts`). Additional languages
|
|
272
|
+
may be added over time; run `graphiti codegen --help` to see the current list.
|
|
273
|
+
|
|
274
|
+
### Semantic Validation (check)
|
|
275
|
+
|
|
276
|
+
Beyond GraphQL schema validation, `check` also warns about:
|
|
277
|
+
|
|
278
|
+
- Connection fields without `first` set (optional but recommended for predictable pagination)
|
|
279
|
+
- Non-filterable fields in `where` clauses
|
|
280
|
+
- Non-sortable fields in `orderBy` clauses
|
|
281
|
+
- Empty selection sets on connections
|
|
282
|
+
- Missing required fields in mutation inputs
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Command Chaining
|
|
287
|
+
|
|
288
|
+
Run multiple commands in a single invocation (session loaded once):
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
graphiti chain -s cases "cd uiapi/query/Case; set first=10; select edges/node/Id; check"
|
|
292
|
+
graphiti chain -s cases --json "select Id; set first=10; check" # JSON array output
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## Describe (SObject Inspection)
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
graphiti describe Case # by name
|
|
301
|
+
graphiti describe # auto-detect from current navigation
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Shows: fields with labels, picklist values, reference targets, required/auto/create-only/filterable/sortable tags, child relationships, filter/orderBy examples.
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## Key Workflows
|
|
309
|
+
|
|
310
|
+
### 1. Query with absolute paths (agent-optimized, no cd needed)
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
graphiti new vscodeOrg --name caseDetail && graphiti use caseDetail
|
|
314
|
+
graphiti select \
|
|
315
|
+
uiapi/query/Case/edges/node/Id \
|
|
316
|
+
uiapi/query/Case/edges/node/Subject.value:subject \
|
|
317
|
+
uiapi/query/Case/edges/node/Status.value:status
|
|
318
|
+
graphiti set uiapi/query/Case first=1 where='{"Id":{"eq":"$caseId"}}'
|
|
319
|
+
graphiti var $caseId uiapi/query/Case/@args/where/Id/eq
|
|
320
|
+
graphiti check && graphiti run --var caseId=500SG00001KZliXYAT
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### 2. Query with navigation (human-friendly)
|
|
324
|
+
|
|
325
|
+
```bash
|
|
326
|
+
graphiti new vscodeOrg --name accounts && graphiti use accounts
|
|
327
|
+
graphiti cd uiapi/query/Account/edges/node
|
|
328
|
+
graphiti ls -l Name AnnualRevenue Industry Phone Owner
|
|
329
|
+
graphiti select Id Name.value:name AnnualRevenue.value:revenue Industry.value:industry
|
|
330
|
+
graphiti set uiapi/query/Account first=10
|
|
331
|
+
graphiti set uiapi/query/Account where='{"AnnualRevenue":{"gt":10000}}'
|
|
332
|
+
graphiti check && graphiti run
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### 3. Create a record (mutation)
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
graphiti new vscodeOrg --mutation --name createOpp && graphiti use createOpp
|
|
339
|
+
graphiti cd uiapi/OpportunityCreate/Record
|
|
340
|
+
graphiti select Id Name.value:name StageName.value:stage
|
|
341
|
+
graphiti cd uiapi/OpportunityCreate/@args
|
|
342
|
+
graphiti var $input input
|
|
343
|
+
graphiti set $input '{"Opportunity":{"Name":"New Deal","CloseDate":"2026-06-30","StageName":"Prospecting"}}'
|
|
344
|
+
graphiti check && graphiti run
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### 4. Aggregate query (count/group)
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
graphiti new vscodeOrg --aggregate --name orderCounts && graphiti use orderCounts
|
|
351
|
+
graphiti select \
|
|
352
|
+
uiapi/aggregate/Order/edges/node/aggregate/Status/value:status \
|
|
353
|
+
uiapi/aggregate/Order/edges/node/aggregate/Id/count/value:orderCount
|
|
354
|
+
graphiti set uiapi/aggregate/Order 'groupBy={"Status":{"group":true}}'
|
|
355
|
+
graphiti check && graphiti run
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
Aggregate queries use `uiapi/aggregate/<SObject>` instead of `uiapi/query/<SObject>`. Fields live under `edges/node/aggregate/<Field>` and expose `value`, `count`, `countDistinct`, and `grouping`. Use `groupBy` to group results.
|
|
359
|
+
|
|
360
|
+
### 5. Chained commands (fastest)
|
|
361
|
+
|
|
362
|
+
```bash
|
|
363
|
+
graphiti new vscodeOrg --name caseDetail
|
|
364
|
+
graphiti chain -s caseDetail 'select uiapi/query/Case/edges/node/Id uiapi/query/Case/edges/node/Subject.value:subject; set uiapi/query/Case first=1 where={"Id":{"eq":"$caseId"}}; var $caseId uiapi/query/Case/@args/where/Id/eq; check; run --var caseId=500SG00001KZliXYAT'
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
## Tips
|
|
370
|
+
|
|
371
|
+
- `show --json` is the single most important command for agents — one call gives everything.
|
|
372
|
+
- `ls -l` shows ObjectInfo metadata: labels, picklist values, reference targets, filterable/sortable.
|
|
373
|
+
- `describe Case` shows a complete SObject view with field metadata and examples.
|
|
374
|
+
- `codegen` generates client types for the session. `--language typescript` (default, alias `ts`) produces TypeScript with picklist unions from ObjectInfo. Pass `--language <lang>` to target additional languages as they are added.
|
|
375
|
+
- Use absolute paths with `select` and `set` to avoid interleaving `cd` calls.
|
|
376
|
+
- `select ls` lists all currently selected fields — useful for debugging.
|
|
377
|
+
- `undo` reverts the last mutation (cd, select, drop, set, var, alias, reset).
|
|
378
|
+
- Pass `-q` / `--quiet` to `select` to suppress confirmation messages in scripts.
|
|
379
|
+
- Salesforce wraps field values in typed objects (`StringValue`, `PicklistValue`, etc.). Use dot-path: `select Name.value:name`.
|
|
380
|
+
- `on:TypeName` is the shell-safe alternative to `[TypeName]` for fragments.
|
|
381
|
+
|
|
382
|
+
## Common Pitfalls
|
|
383
|
+
|
|
384
|
+
### Shell variable expansion with `$`
|
|
385
|
+
|
|
386
|
+
When using `where.Field=$varName`, **always single-quote** the argument to prevent the shell from expanding `$varName` to an empty string:
|
|
387
|
+
|
|
388
|
+
```bash
|
|
389
|
+
# WRONG — shell expands $status to empty string:
|
|
390
|
+
graphiti set uiapi/query/Case where.Status=$status
|
|
391
|
+
|
|
392
|
+
# CORRECT — single quotes prevent expansion:
|
|
393
|
+
graphiti set uiapi/query/Case 'where.Status=$status'
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
The CLI will warn if it detects an empty where value (likely from shell expansion).
|
|
397
|
+
|
|
398
|
+
### Mutation payloads don't include relationships
|
|
399
|
+
|
|
400
|
+
Mutation create/update payloads only return the flat record fields. You cannot select related objects (e.g., `Account/Name`) from a mutation result. Use a follow-up query with the returned `Id` to fetch related data.
|
|
401
|
+
|
|
402
|
+
### User scope limitation
|
|
403
|
+
|
|
404
|
+
The `User` SObject only supports `scope=EVERYTHING`, not `scope=MINE`. To get the current user, use `where.Id=$userId` and pass the user's ID at runtime.
|
|
405
|
+
|
|
406
|
+
### Parallel agent builds
|
|
407
|
+
|
|
408
|
+
When multiple agents build queries concurrently, the global active session causes cross-contamination. Each `new` command changes the active session, so another agent's `select`/`set` commands silently target the wrong session.
|
|
409
|
+
|
|
410
|
+
**Always use `-s` when running in parallel:**
|
|
411
|
+
|
|
412
|
+
```bash
|
|
413
|
+
# WRONG — agents race on the active session:
|
|
414
|
+
graphiti new vscodeOrg --name query-a --force
|
|
415
|
+
graphiti select uiapi/query/Case/edges/node/Id # may target query-b!
|
|
416
|
+
|
|
417
|
+
# CORRECT — explicit session targeting:
|
|
418
|
+
graphiti new vscodeOrg --name query-a --force
|
|
419
|
+
graphiti -s query-a select uiapi/query/Case/edges/node/Id
|
|
420
|
+
graphiti -s query-a set uiapi/query/Case first=10
|
|
421
|
+
graphiti -s query-a check --codegen
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
For sequential single-agent workflows, the active session is safe to use implicitly.
|