Docs
Launch GraphOS Studio

2. Add the GraphQL Schema


This tutorial uses a modified version of the you build as part of the Apollo full-stack tutorial. You can visit that server's Apollo Studio Sandbox Explorer to explore its schema without needing to be logged in:

The Sandbox query explorer

You'll know that this Sandbox instance is pointed at our server because its URL, https://apollo-fullstack-tutorial.herokuapp.com, is in the box at the top left of the page. If Sandbox is properly connected, you'll see a green dot:

A closeup of the URL box with a dot indicating it's connected

The schema defines which your server can execute. At the top left, click the schema icon to get an overview of your schema:

The schema icon to click

In the Reference tab, you can now see a list of all of the things available to you as a consumer of this API, along with available on all objects:

Apollo sandbox showing the schema reference

Setup Codegen CLI

The 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 symbolic link to the executable in your project root.

If you use Swift packages through Xcode, you can right-click on your project in the Xcode file explorer, revealing an Install CLI plugin command. Selecting this command presents a dialog allowing you to grant the plugin "write" access to your project directory.

Where to find the SPM plugin commands in Xcode

After the plugin installs, it creates a symbolic link to the Codegen CLI (named apollo-ios-cli) 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 only works if the compiled CLI executable exists. This is generally located in your Xcode Derived Data or the .build folder. If these are cleared, you can rerun the Install CLI plugin to rebuild the CLI executable.

Note: Xcode 14.3 has a bug where the Install CLI plugin command does not show up in the menu when right-clicking on your project which is being tracked here. If you experience this issue an alternative is to use another version of Xcode, or follow the instructions to get a pre-built binary of the CLI on the Codegen CLI page.

Create your Codegen Configuration

Next we need to setup our codegen configuration file. To do this run the following command in Terminal from project directory:

./apollo-ios-cli init --schema-namespace RocketReserverAPI --module-type swiftPackageManager

This generates a basic apollo-codegen-config.json file for our project.

Download your server's schema

Next we need to download the schema for our project to use. To do so, first we need to update our apollo-codegen-config.json to include a schemeDownloadConfiguration. Add the following JSON to the end of the config file after the output object:

"schemaDownloadConfiguration": {
"downloadMethod": {
"introspection": {
"endpointURL": "https://apollo-fullstack-tutorial.herokuapp.com/graphql",
"httpMethod": {
"POST": {}
},
"includeDeprecatedInputValues": false,
"outputFormat": "SDL"
}
},
"downloadTimeout": 60,
"headers": [],
"outputPath": "./graphql/schema.graphqls"
}

For more information about downloading schemas, see the Downloading a Schema documentation.

Now that we have updated our config, we can download the schema by running the following command in Terminal:

./apollo-ios-cli fetch-schema

After running this command you should see a graphql folder in your project directory containing a schema.graphqls file.

In the next step you will write your first query.

Previous
1. Configure your project
Next
3. Write your first query
Edit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company