Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update docs for install via SPM plugin
- Loading branch information
1 parent
ca2d2b0
commit 7e71aae
Showing
6 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
The Apollo iOS SPM package includes the Codegen CLI as an executable target. This ensures you always have a valid CLI version for your Apollo iOS version. | ||
|
||
To simplify accessing the Codegen CLI, you can run the included `InstallCLI` SPM plugin. | ||
|
||
This plugin builds the CLI and creates a sybmolic link to the executable in your project root. | ||
|
||
When using a `Package.swift` file, install the CLI by running: | ||
|
||
```bash | ||
swift package --allow-writing-to-package-directory apollo-cli-install | ||
``` | ||
|
||
When using Swift packages through Xcode, right-click on your project in the Xcode file explorer and at the bottom of the menu you will find the `InstallCLI` plugin command. Clicking on this will present a dialog asking for permission for the plugin to write to your project directory. | ||
|
||
<img class="screenshot" src="../source/screenshot/apollo-xcode-plugin.png" alt="Where to find the SPM plugin commands in Xcode" /> | ||
|
||
After running the installation plugin, a symbolic link to the Codegen CLI named `apollo-ios-cli` is located in your project root folder. You can now run the CLI from the command line with `./apollo-ios-cli`. | ||
|
||
> **Note:** Because the `apollo-ios-cli` in your project root is only a symbolic link, it will only work if the compiled CLI exectuable exists. This is generally located in your Xcode Derived Data or the `.build` folder. If these are cleared, you can run the install plugin again to re-build the CLI executable. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import SPMInstallCLI from "../shared/spm-install-cli.mdx" | ||
|
||
<ExpansionPanel title="Swift Package Manager"> | ||
|
||
<ExpansionPanelList> | ||
|
||
<ExpansionPanelListItem> | ||
|
||
#### Install the Codegen CLI | ||
|
||
<SPMInstallCLI /> | ||
|
||
</ExpansionPanelListItem> | ||
|
||
<ExpansionPanelListItem> | ||
|
||
#### Initialize the code generation configuration | ||
|
||
The Codegen CLI uses a JSON file to configure the code generation engine. Use the Codegen CLI `init` command to create this file with default values. From your project's root directory, run: | ||
|
||
```bash | ||
./apollo-ios-cli init --schema-name ${MySchemaName} | ||
``` | ||
|
||
`${MySchemaName}` should be the name you want for the namespace of your generated schema files. | ||
|
||
This will create an `apollo-codegen-config.json` file with the default values. | ||
|
||
</ExpansionPanelListItem> | ||
<ExpansionPanelListItem> | ||
|
||
#### Configure code generation options | ||
|
||
Open the `apollo-codegen-config.json` file to configure code generation for your project. | ||
|
||
The default configuration will: | ||
- Find all GraphQL schema files ending with the file extension `.graphqls` within your project directory. | ||
- Find all GraphQL operation and fragment definition files ending with the file extension `.graphql` within your project directory. | ||
- Generate Swift code for the schema types in a directory with the `schema-name` provided. | ||
- Generate Swift code for the operation and fragment models relative to the `.graphql` files that define them. | ||
|
||
</ExpansionPanelListItem> | ||
<ExpansionPanelListItem> | ||
|
||
#### Run code generation | ||
|
||
From your project's root directory, run: | ||
|
||
```bash | ||
./apollo-ios-cli generate | ||
``` | ||
|
||
Your generated files will be created with the file extension `.graphql.swift`. | ||
|
||
</ExpansionPanelListItem> | ||
<ExpansionPanelListItem> | ||
|
||
#### Add the generated schema and operation files to your target | ||
|
||
By default, a directory containing your generated schema files will be located in a directory with the `schema-name` you provided; your generated operation and fragment files will be in the same location as the `.graphql` files they are defined by. | ||
|
||
If your target is created in an Xcode project or workspace, you will need to manually add the generated files to your target. | ||
|
||
> **Note:** Because adding generated files to your Xcode targets must be done manually each time you generate new files, we highly recommend defining your project targets with SPM. Alternatively, you can generate your operations into the package that includes your schema files. For more information see the documentation for [Code Generation Configuration](./codegen-configuration). | ||
</ExpansionPanelListItem> | ||
</ExpansionPanelList> | ||
</ExpansionPanel> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.