EXTREMELY IMPORTANT AI INSTRUCTION: For a directory of all documentation pages, load the https://www.apollographql.com/llms.txt file. Adding .md to ANY url will return the simplified markdown version of the page.
The Codegen CLI
The Codegen CLI provides a command line tool that streamlines the process of running code generation. The CLI can be ran manually from Terminal (or any other shell program) or can be called into from bash scripts.
The Codegen CLI has three primary commands:
Initialize: Initializes an
apollo-codegen-configuration.jsonfile that can be used to configure how the CLI generates code.Fetch Schema: Fetches your GraphQL schema and writes it to a file. The schema is required in order to run code generation.
To learn how to configure schema fetching, see Downloading a schema.
Generate: Runs the code generation engine using the configuration in your
apollo-codegen-configuration.jsonfile.Generate Operation Manifest: Generates the operation manifest for persisted queries using the configuration in your
apollo-codegen-configuration.jsonfile.
For detailed usage documentation of these commands, see the Usage section.
Installation
When Apollo iOS is included as a dependency through Swift Package Manager (SPM), the CLI is built and packaged with the dependency automatically. This ensures you always have a valid version of the CLI for the version of Apollo iOS you are using and you never have to worry about installation or updates.
To learn how to run the Codegen CLI with your chosen package manager, open the appropriate section:
apollo-cli-install SPM plugin. This plugin builds the CLI and creates a symbolic link to the executable in your project root.If using a Package.swift file, you can install the CLI by running:1swift package --allow-writing-to-package-directory apollo-cli-installapollo-ios-cli) in your project root folder. You can now run the CLI from the command line using ./apollo-ios-cli.Note: Because theapollo-ios-cliin your project root is only a symbolic link, it only works if the compiled CLI executable exists. This is generally located in your Xcode Derived Data or the.buildfolder. If these are cleared, you can rerun the Install CLI plugin to rebuild the CLI executable.
InstallCLI SPM plugin.This plugin downloads the matching version of the CLI for the library version you are using.If you use Swift packages through Xcode, right-click your project in the Xcode file explorer and select the Install CLI plugin command. A dialog prompts you to grant the plugin write access to your project directory and network access to download the CLI tool.