Browse Source

docs: Add docs on schema CLI command

Michael Bromley 3 months ago
parent
commit
a53578e276

+ 72 - 0
docs/docs/guides/developer-guide/cli/index.md

@@ -265,6 +265,77 @@ yarn vendure migrate -g my-migration -o ./custom/migrations
 | | `--revert` | Revert the last migration | `vendure migrate --revert` |
 | | `--revert` | Revert the last migration | `vendure migrate --revert` |
 | `-o` | `--output-dir <path>` | Custom output directory for migrations | `vendure migrate -g my-migration -o ./migrations` |
 | `-o` | `--output-dir <path>` | Custom output directory for migrations | `vendure migrate -g my-migration -o ./migrations` |
 
 
+## The Schema Command
+
+:::info
+The `schema` command was added in Vendure v3.5
+:::
+
+The `schema` command allows you to generate a schema file for your Admin or Shop APIs, in either the GraphQL schema definition language (SDL)
+or as JSON.
+
+This is useful when integrating with GraphQL tooling such as your [IDE's GraphQL plugin](/guides/getting-started/graphql-intro/#ide-plugins).
+
+### Interactive Mode
+
+From your project's **root directory**, run:
+
+<Tabs groupId="package-manager">
+<TabItem value="npm" label="npm" default>
+
+```bash
+npx vendure schema
+```
+
+</TabItem>
+<TabItem value="yarn" label="yarn">
+
+```bash
+yarn vendure schema
+```
+
+</TabItem>
+</Tabs>
+
+### Non-Interactive Mode
+
+To automate or quickly generate a schema in one command
+
+<Tabs groupId="package-manager">
+<TabItem value="npm" label="npm" default>
+
+```bash
+# Create a schema file in SDL format for the Admin API
+npx vendure schema --api admin
+
+# Create a JSON format schema of the Shop API
+npx vendure migrate --api shop --format json
+```
+
+</TabItem>
+<TabItem value="yarn" label="yarn">
+
+```bash
+# Create a schema file in SDL format for the Admin API
+yarn vendure schema --api admin
+
+# Create a JSON format schema of the Shop API
+yarn vendure migrate --api shop --format json
+```
+
+</TabItem>
+</Tabs>
+
+#### Migrate Command Options
+
+| Flag | Long Form             | Description                                     | Example                                                        |
+|------|-----------------------|-------------------------------------------------|----------------------------------------------------------------|
+| `-a` | `--api <admin,shop>`  | Select the API (required)                       | `vendure schema --api admin`                                   |
+| `-d` | `--dir <dir>`         | Select the output dir (defaults to current dir) | `vendure schema --api admin --dir ../..`                       |
+| `-n` | `--file-name <name>`  | The name of the generated file                  | `vendure schema --api admin --file-name introspection.graphql` |
+| `-f` | `--format <sdl,json>` | The output format (defaults to SDL)             | `vendure schema --api admin --format json`                     |
+
+
 ## Getting Help
 ## Getting Help
 
 
 To see all available commands and options:
 To see all available commands and options:
@@ -273,4 +344,5 @@ To see all available commands and options:
 npx vendure --help
 npx vendure --help
 npx vendure add --help
 npx vendure add --help
 npx vendure migrate --help
 npx vendure migrate --help
+npx vendure schema --help
 ```
 ```

+ 5 - 0
docs/docs/guides/getting-started/graphql-intro/index.mdx

@@ -542,6 +542,11 @@ as you write them. This is a huge productivity boost, and is **highly recommende
 - [GraphQL extension for VS Code](https://marketplace.visualstudio.com/items?itemName=GraphQL.vscode-graphql)
 - [GraphQL extension for VS Code](https://marketplace.visualstudio.com/items?itemName=GraphQL.vscode-graphql)
 - [GraphQL plugin for IntelliJ](https://plugins.jetbrains.com/plugin/8097-graphql) (including WebStorm)
 - [GraphQL plugin for IntelliJ](https://plugins.jetbrains.com/plugin/8097-graphql) (including WebStorm)
 
 
+:::cli
+Run the `npx vendure schema` to generate a GraphQL schema file that your IDE plugin
+can use to provide autocomplete.
+:::
+
 ## Code generation
 ## Code generation
 
 
 Code generation means the automatic generation of TypeScript types based on your GraphQL schema and your GraphQL operations. This is a very powerful feature that allows you to write your code in a type-safe manner, without you needing to manually write any types for your API calls.
 Code generation means the automatic generation of TypeScript types based on your GraphQL schema and your GraphQL operations. This is a very powerful feature that allows you to write your code in a type-safe manner, without you needing to manually write any types for your API calls.

+ 7 - 3
docs/docs/guides/how-to/codegen/index.md

@@ -10,6 +10,9 @@ To do this, we will use [Graphql Code Generator](https://the-guild.dev/graphql/c
 
 
 :::cli
 :::cli
 Use `npx vendure add` and select "Set up GraphQL code generation" to quickly set up code generation.
 Use `npx vendure add` and select "Set up GraphQL code generation" to quickly set up code generation.
+
+You can then run `npx vendure schema` to generate a `schema.graphql` file in your root
+directory.
 :::
 :::
 
 
 :::note
 :::note
@@ -36,9 +39,10 @@ import type {CodegenConfig} from '@graphql-codegen/cli';
 
 
 const config: CodegenConfig = {
 const config: CodegenConfig = {
     overwrite: true,
     overwrite: true,
-    // This assumes your server is running on the standard port
-    // and with the default admin API path. Adjust accordingly.
-    schema: 'http://localhost:3000/admin-api',
+    // To generate this schema file, run `npx vendure schema`
+    // whenever your schema changes, e.g. after adding custom fields
+    // or API extensions
+    schema: 'schema.graphql',
     config: {
     config: {
         // This tells codegen that the `Money` scalar is a number
         // This tells codegen that the `Money` scalar is a number
         scalars: { Money: 'number' },
         scalars: { Money: 'number' },