title |
---|
2. Add the GraphQL Schema |
import SPMXcodeInstallCLI from "../../shared/cli-install/spm-xcode.mdx"
This tutorial uses a modified version of the GraphQL server 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:
You'll know that this Sandbox instance is pointed at our server because its URL, https://apollo-fullstack-tutorial.herokuapp.com/graphql
, is in the box at the top left of the page. If Sandbox is properly connected, you'll see a green dot:
The schema defines which GraphQL operations your server can execute. At the top left, click the schema icon to get an overview of your schema:
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 fields on all objects:
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.
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.
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.