You are viewing documentation for a previous version of this software.

Switch to the latest stable version.

Downloading a schema


Apollo iOS requires a GraphQL schema file as input to its code generation process. You can provide your schema either as a JSON file (most commonly the result of an introspection query) or as a .graphqls file that uses GraphQL SDL syntax. Conventionally, this file is named schema.json or schema.graphqls (depending on its format), and you store it in the same folder as your project's App:

Location of schema file in project

📣 Check it out: Instead of writing the scripts below in Bash, try using our new Swift Scripting Library, now in Beta! It supports downloading a schema and generating code.

You can use the Apollo CLI to download a GraphQL schema by sending an introspection query to the server. If you've installed the CLI globally, you can use the following command to download your schema:

sh
1apollo schema:download --endpoint=http://localhost:8080/graphql schema.json

Note that if you're using the local version set up for codegen, you should use the same method you're using in the Add a code generation build step instructions to access that specific CLI. For example, if you're using CocoaPods, you can set it up like this to download your schema:

Bash
1SCRIPT_PATH="${PODS_ROOT}/Apollo/scripts"
2cd "${SRCROOT}/${TARGET_NAME}"
3"${SCRIPT_PATH}"/run-bundled-codegen.sh schema:download --endpoint=http://localhost:8080/graphql schema.json

If needed, you can use the header option to add additional HTTP headers to the request. For example, to include an authentication token, use --header "Authorization: Bearer <token>":

sh
1[your apollo version] schema:download --endpoint=http://localhost:8080/graphql --header="Authorization: Bearer <token>"
Feedback

Edit on GitHub

Forums