Auto-generate API.Swift file in Xcode project.

Chandan
2 min readJan 30, 2022

--

I want to go index page of this tutorial series.

This is very important part of implementing Apollo GraphQL in iOS project.

  • Create new Run script phase in your Xcode project. Follow the steps.👇
  1. Click your project in your file hierarchy and select project in targets.
  2. Then click on build phases.
  3. Click + icon.
  4. Then click New run script phase.

Example 👇

Create new run script phase example.

5. Then rename your new run script → Apollo GraphQL run script

Copy this 👇 script code and paste in Xcode Apollo GraphQL run script

Run script code

After building this project you got 1 error something like this → Command PhaseScriptExecution failed with a nonzero exit code

To solve this you need to make new empty file name is quary.graphql

Select other section Empty file.

then add queries into your GraphQL file like this.👇🏼

And then build you project.

your project build successful but API.swift file is not comings.

your API.swift file is not available in your project its available in your local storage ok. so drag & drop into your project 👇🏼

Drag & Drop Api.swift File

Now if you edit your Query.graphql file (Add & Remove) Query, then you will see changes on your API.Swift file.

Your API.swift file should be look something like this 👇🏼

API.swift file

Congratulations Again. 🥳 🎉 👏 🙌 🍾 🥂 🎊 .

You Achieved bigger achievement.

--

--