|
| 1 | +--- |
| 2 | +title: "Fusion CLI Documentation" |
| 3 | +--- |
| 4 | + |
| 5 | +The Fusion Command Line Interface is a tool designed to assist the development and management of APIs using Fusion. This documentation provides a comprehensive guide to the Fusion CLI, covering installation, commands, options, and usage examples to help you effectively utilize the tool in your projects. |
| 6 | + |
| 7 | +## Introduction |
| 8 | + |
| 9 | +Fusion CLI is a command-line tool that assists developers in composing, packaging, and managing federated schemas for Fusion gateways. |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +To install the Fusion CLI, ensure you have the .NET SDK installed on your machine. Then, install the CLI globally using the .NET tool command: |
| 14 | + |
| 15 | +```bash |
| 16 | +dotnet tool install -g HotChocolate.Fusion.CommandLine |
| 17 | +``` |
| 18 | + |
| 19 | +This command installs the Fusion CLI globally, making it accessible from any directory in your command line. |
| 20 | + |
| 21 | +## Commands |
| 22 | + |
| 23 | +### `fusion compose` |
| 24 | + |
| 25 | +The `compose` command is used to create or update a Fusion gateway package (`.fgp` file) by composing multiple APIs packages (`.fsp` files). This package is then used by the Fusion gateway to serve a unified schema. |
| 26 | + |
| 27 | +**Description:** |
| 28 | + |
| 29 | +Composes multiple APIs into a Fusion gateway package. |
| 30 | + |
| 31 | +**Usage:** |
| 32 | + |
| 33 | +```bash |
| 34 | +fusion compose [options] |
| 35 | +``` |
| 36 | + |
| 37 | +**Options:** |
| 38 | + |
| 39 | +- `-p`, `--package`, `--package-file <package-file>` (REQUIRED): Specifies the path to the Fusion gateway package file (`gateway.fgp`). This file will be created or updated by the compose command. |
| 40 | +- `-s`, `--subgraph`, `--subgraph-package-file <subgraph-package-file>`: Specifies the path to a subgraph package file (`.fsp`) to include in the composition. This option can be used multiple times to add multiple subgraphs. |
| 41 | +- `--package-settings`, `--package-settings-file`, `--settings <package-settings-file>`: Specifies the path to a Fusion package settings file (`fusion-subgraph.json`). This file contains additional settings for the composition. |
| 42 | +- `-w`, `--working-directory <working-directory>`: Sets the working directory for the command. Defaults to the current executing directory. |
| 43 | +- `--enable-nodes`: Enables the Node interface feature in the gateway, allowing it to understand `node(id: ...)` queries. |
| 44 | +- `-r`, `--remove <subgraph-name>`: Removes a specified subgraph from the existing composition in the gateway package. |
| 45 | +- `-?`, `-h`, `--help`: Shows help and usage information for the command. |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +### `fusion subgraph` |
| 50 | + |
| 51 | +The `subgraph` command group contains commands related to subgraph management, such as packaging subgraphs for composition. |
| 52 | + |
| 53 | +#### `fusion subgraph pack` |
| 54 | + |
| 55 | +The `pack` command creates a Fusion subgraph package (`.fsp` file) from a subgraph's schema and configuration. This package is then used in the composition process. |
| 56 | + |
| 57 | +**Description:** |
| 58 | + |
| 59 | +Creates a Fusion subgraph package from a subgraph's schema and configuration files. |
| 60 | + |
| 61 | +**Usage:** |
| 62 | + |
| 63 | +```bash |
| 64 | +fusion subgraph pack [options] |
| 65 | +``` |
| 66 | + |
| 67 | +**Options:** |
| 68 | + |
| 69 | +- `-p`, `--package`, `--package-file <package-file>`: Specifies the output path for the subgraph package file (`YourService.fsp`). Defaults to `<SourceName>.fsp` if not specified. |
| 70 | +- `-s`, `--schema`, `--schema-file <schema-file>`: Specifies the path to the subgraph's schema file (`schema.graphql`). |
| 71 | +- `-c`, `--config`, `--config-file <config-file>`: Specifies the path to the subgraph's configuration file (`subgraph-config.json`). |
| 72 | +- `-e`, `--extension`, `--extension-file <extension-file>`: Specifies paths to any schema extension files to include. This option can be used multiple times for multiple files. |
| 73 | +- `-w`, `--working-directory <working-directory>`: Sets the working directory for the command. Defaults to the current executing directory. |
| 74 | +- `-?`, `-h`, `--help`: Shows help and usage information for the command. |
| 75 | + |
| 76 | +## Examples |
| 77 | + |
| 78 | +This section provides practical examples of using the Fusion CLI commands in common scenarios. |
| 79 | + |
| 80 | +### Example 1: Packing a Downstream Service |
| 81 | + |
| 82 | +Suppose you have a subgraph named `Products` with a schema file `schema.graphql` and a configuration file `subgraph-config.json`. To create a subgraph package, navigate to the subgraph's directory and run: |
| 83 | + |
| 84 | +```bash |
| 85 | +fusion subgraph pack |
| 86 | +``` |
| 87 | + |
| 88 | +In case your schema and configuration files have different names or are located in a different directory, you can specify them using the `-s` and `-c` options: |
| 89 | + |
| 90 | +```bash |
| 91 | +fusion subgraph pack -s other-schema.graphql -c config.json |
| 92 | +``` |
| 93 | + |
| 94 | +This command generates a `Products.fsp` package file in the current directory. |
| 95 | + |
| 96 | +### Example 2: Composing a Gateway Package |
| 97 | + |
| 98 | +To compose a Fusion gateway package from multiple subgraph packages, use the `compose` command. For example, to compose the `Products` and `Orders` subgraphs into a gateway package named `gateway.fgp`, run: |
| 99 | + |
| 100 | +```bash |
| 101 | +fusion compose -p gateway.fgp -s ../Products/Products.fsp -s ../Orders/Orders.fsp |
| 102 | +``` |
| 103 | + |
| 104 | +This command creates or updates the `gateway.fgp` file with the composed schema from both subgraphs. |
| 105 | + |
| 106 | +### Example 3: Removing a Downstream Service from the Composition |
| 107 | + |
| 108 | +If you need to remove the `Orders` subgraph from an existing gateway package, use the `--remove` option: |
| 109 | + |
| 110 | +```bash |
| 111 | +fusion compose -p gateway.fgp -r Orders |
| 112 | +``` |
| 113 | + |
| 114 | +This command updates `gateway.fgp`, removing the `Orders` subgraph from the composition. |
| 115 | + |
| 116 | +### Example 4: Enabling Node Interface Support |
| 117 | + |
| 118 | +To enable the Node interface feature in your gateway, allowing it to handle `node` queries, include the `--enable-nodes` flag during composition: |
| 119 | + |
| 120 | +```bash |
| 121 | +fusion compose -p gateway.fgp -s ../Products/Products.fsp --enable-nodes |
| 122 | +``` |
| 123 | + |
| 124 | +### Example 5: Specifying Working Directory |
| 125 | + |
| 126 | +If your schema and configuration files are located in a different directory, you can specify the working directory using `-w`: |
| 127 | + |
| 128 | +```bash |
| 129 | +fusion subgraph pack -s schema.graphql -c subgraph-config.json -w /path/to/subgraph |
| 130 | +``` |
| 131 | + |
| 132 | +## Additional Resources |
| 133 | + |
| 134 | +- **Fusion Documentation:** Explore the [official Fusion documentation](/docs/fusion/v14) for in-depth guides and references. |
| 135 | +- **Fusion Quick Start Guide:** Get started with Fusion by following the [Quick Start Guide](/docs/fusion/v16/quick-start). |
| 136 | +- **ChilliCream Community:** Join the [ChilliCream community](https://slack.chillicream.com) to ask questions, share experiences, and contribute to the project. |
0 commit comments