w3resource

Downloading a schema


Apollo iOS requires a GraphQL schema file as input to the code generation process. A schema file is a JSON file that contains the results of an introspection query. Conventionally this file is called schema.json, and you store it next to the .graphql files in your target.

Note: Instead of writing the rest of this in Bash, try using our new Swift Scripting Library, now in Beta! It supports downloading a schema and generating code.

You can use apollo from the apollo-cli package 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:

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

Note that if you're using the local version set up for codegen, you'll want to use the same method you're using in the Adding 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:

SCRIPT_PATH="${PODS_ROOT}/Apollo/scripts"
cd "${SRCROOT}/${TARGET_NAME}"
"${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>":

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

Previous: Define additional mutations
Next: Enable authentication



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/apollo-graphql/downloading-a-schema.php