@hygraph/cli 0.0.6 → 0.0.7
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/README.md +146 -23
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,42 +1,165 @@
|
|
|
1
1
|
# @hygraph/cli
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Manage your Hygraph schema as code. Describe the schema in TypeScript, review
|
|
6
|
+
what would change, and apply it as one migration.
|
|
7
|
+
|
|
8
|
+
> [!WARNING]
|
|
9
|
+
> The CLI is in **alpha** and under active development. Not every field type
|
|
10
|
+
> and platform capability is supported yet, and commands and the config
|
|
11
|
+
> format can still change between releases.
|
|
12
|
+
>
|
|
13
|
+
> **We'd love to hear your feedback: what works, what is missing, what got in
|
|
14
|
+
> your way.** Write to any of us:
|
|
15
|
+
>
|
|
16
|
+
> - Danijel Vincijanović, [danijel.vincijanovic@hygraph.com](mailto:danijel.vincijanovic@hygraph.com)
|
|
17
|
+
> - Jonas Faber, [jonas@hygraph.com](mailto:jonas@hygraph.com)
|
|
18
|
+
> - Saumya Vasuthevan, [saumya.vasuthevan@hygraph.com](mailto:saumya.vasuthevan@hygraph.com)
|
|
19
|
+
|
|
20
|
+
## Setup
|
|
21
|
+
|
|
22
|
+
Prerequisite is Node 22 or newer.
|
|
5
23
|
|
|
6
24
|
```bash
|
|
7
25
|
npm i -D @hygraph/cli
|
|
8
|
-
npx hygraph --help
|
|
9
26
|
```
|
|
10
27
|
|
|
11
|
-
|
|
28
|
+
The CLI needs a permanent auth token from your project's settings in Studio:
|
|
29
|
+
|
|
30
|
+
- a **permanent auth token** **(PAT)**
|
|
31
|
+
- Create one in **Project Settings > Permanent Auth Tokens > Add token**
|
|
32
|
+
- Then enable all management permissions for it
|
|
33
|
+
- Put the token in the `HYGRAPH_TOKEN` environment variable. The config
|
|
34
|
+
reads it from there, so the token never ends up in a file you commit.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
export HYGRAPH_TOKEN="…"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Start from your project
|
|
41
|
+
|
|
42
|
+
`export` writes your project's current schema as a config file:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npx hygraph export --project <project-id> --endpoint <endpoint> --out hygraph.config.ts
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
To run the `export` command, you need to provide the project ID and endpoint.
|
|
49
|
+
|
|
50
|
+
- Find the **project ID** in **Project Settings > Project**
|
|
51
|
+
- The project's **Management API endpoint**
|
|
52
|
+
- Find it in **Project Settings > Endpoints > Management API**, such as
|
|
53
|
+
`https://management-eu-central-1.hygraph.com/graphql`
|
|
54
|
+
|
|
55
|
+
After running the `export` command, you can check the exported `master`
|
|
56
|
+
environment in the `hygraph.config.ts` file.
|
|
57
|
+
|
|
58
|
+
Then run the `plan` command. It should show no changes, because the current
|
|
59
|
+
config matches your project:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npx hygraph plan
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Commit `hygraph.config.ts`. From here on it is the source of your schema.
|
|
66
|
+
|
|
67
|
+
## Make a change
|
|
68
|
+
|
|
69
|
+
Edit the config. To add a field to a model you already have, add it to the
|
|
70
|
+
model's `fields`.
|
|
71
|
+
|
|
72
|
+
For a new model, define it with its fields:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
const Post = define.model({
|
|
76
|
+
apiId: "Post",
|
|
77
|
+
apiIdPlural: "Posts",
|
|
78
|
+
displayName: "Post",
|
|
79
|
+
fields: [
|
|
80
|
+
define.field.singleLine({ apiId: "title", displayName: "Title" }),
|
|
81
|
+
define.field.boolean({ apiId: "featured", displayName: "Featured" }),
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Then add it to the environment's `models`. A model that isn't in that list is
|
|
87
|
+
not part of the schema:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
const environment = define.environment({
|
|
91
|
+
// …
|
|
92
|
+
models: [Post],
|
|
93
|
+
});
|
|
94
|
+
```
|
|
12
95
|
|
|
13
|
-
|
|
14
|
-
the permanent auth token and the Management API endpoint from the
|
|
15
|
-
project's settings in Studio.
|
|
96
|
+
See what would change:
|
|
16
97
|
|
|
17
98
|
```bash
|
|
18
|
-
export HYGRAPH_TOKEN="…"
|
|
19
|
-
npx hygraph export --project <id> --endpoint <url> --out hygraph.config.ts
|
|
20
99
|
npx hygraph plan
|
|
21
100
|
```
|
|
22
101
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
102
|
+
Apply it:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npx hygraph apply
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`apply` shows the plan again and asks you to confirm. All changes go to
|
|
109
|
+
Hygraph as one migration. If it fails, nothing is applied.
|
|
110
|
+
|
|
111
|
+
### Deleting things
|
|
112
|
+
|
|
113
|
+
A change that deletes data, such as removing a model or a field, needs
|
|
114
|
+
`--prune`. Without it, `apply` stops and shows what would be deleted:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
npx hygraph apply --prune
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### In CI
|
|
121
|
+
|
|
122
|
+
`apply` does not ask for confirmation when `CI` or `TF_BUILD` is set, which
|
|
123
|
+
most CI providers do. Elsewhere, pass `--yes`.
|
|
124
|
+
|
|
125
|
+
To apply exactly the plan someone reviewed, save it and pass it to `apply`:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npx hygraph plan --out plan.json
|
|
129
|
+
npx hygraph apply --plan plan.json
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`apply` refuses the saved plan if the config or the live schema has changed
|
|
133
|
+
since. Run `plan` again in that case.
|
|
134
|
+
|
|
135
|
+
## What's supported
|
|
27
136
|
|
|
28
|
-
|
|
137
|
+
- **Schema:** models, components, enumerations, taxonomies, locales and
|
|
138
|
+
stages.
|
|
139
|
+
- **Field types:** single line, multi line, markdown, slug, rich text, int,
|
|
140
|
+
float, boolean, date, date and time, color, JSON, location, enumeration,
|
|
141
|
+
taxonomy, asset, one-way and two-way references, component and component
|
|
142
|
+
union.
|
|
143
|
+
- **Not yet and incoming:** union references, remote fields and remote
|
|
144
|
+
sources, vector fields, custom fields on the Asset model, content queries
|
|
145
|
+
and segments.
|
|
29
146
|
|
|
30
|
-
|
|
147
|
+
`export` still writes a field the CLI doesn't support, as
|
|
148
|
+
`define.field.unsupported`. The CLI leaves it as it is. To change it, use
|
|
149
|
+
Studio.
|
|
150
|
+
|
|
151
|
+
## Commands
|
|
31
152
|
|
|
32
153
|
```
|
|
33
|
-
hygraph
|
|
34
|
-
hygraph
|
|
35
|
-
hygraph
|
|
36
|
-
hygraph
|
|
37
|
-
hygraph export write a live environment out as TypeScript
|
|
38
|
-
hygraph whoami show what the current token is and can do
|
|
154
|
+
hygraph export write a live environment out as a config
|
|
155
|
+
hygraph whoami show which project and environment the token reaches
|
|
156
|
+
hygraph plan show what would change against the environment
|
|
157
|
+
hygraph apply apply the plan as one migration
|
|
39
158
|
```
|
|
40
159
|
|
|
41
|
-
|
|
42
|
-
|
|
160
|
+
`hygraph pull` and `hygraph validate` are coming. Run
|
|
161
|
+
`npx hygraph <command> --help` for every option.
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT
|
package/dist/version.js
CHANGED