You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/installation.md
+35-45Lines changed: 35 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,11 +16,11 @@ Follow along with these steps (described in detail below) to use Apollo iOS in y
16
16
17
17
## Installing the Apollo framework
18
18
19
-
You can install `Apollo.framework` into your project using [Swift Package Manager](#swift-package-manager-installation), [CocoaPods](#cocoapods-installation), [carthage](#carthage-installation), or by [manually integrating it with Xcode](#manual-integration).
19
+
You can install `Apollo.framework` into your project using [Swift Package Manager](#swift-package-manager-installation), [CocoaPods](#cocoapods-installation), [Carthage](#carthage-installation), or by [manually integrating it with Xcode](#manual-integration).
20
20
21
21
### Swift Package Manager Installation
22
22
23
-
> **NOTE**: These instructions are intended for usage on Xcode 11 and higher. Xcode 11 is the first version of Xcode that integrates Swift Package manager and makes it _way_ easier to use than it was at the command line. If you are using older versions of Xcode, we recommend using [CocoaPods](#CocoaPods-Installation)
23
+
> **NOTE**: These instructions are intended for usage on Xcode 11 and higher. Xcode 11 is the first version of Xcode that integrates Swift Package manager and makes it _way_ easier to use than it was at the command line. If you are using older versions of Xcode, we recommend using [CocoaPods](#cocoapods-installation)
24
24
25
25
1. Go to **File > Swift Packages > Add Package Dependency... **
26
26
@@ -143,35 +143,28 @@ If you have the Xcode add-ons installed, you can use the Xcode companion view to
143
143
144
144
## Adding a code generation build step
145
145
146
-
In order to invoke `apollo`as part of the Xcode build process, create a build step that runs before "Compile Sources" to invoke `apollo` through the `check-and-run-apollo-cli.sh` wrapper script.
146
+
Code generation uses your `.graphql` files to generate API code that will help you send queries, subscriptions, and mutations, as well as parse and cache responses. To run code generation as part of the Xcode build process, you need to create a build step that runs before "Compile Sources" to invoke a wrapper script.
147
147
148
-
The main reason for calling the wrapper is to check whether the version of `apollo`installed on your system is compatible with the framework version installed in your project, and to warn you if it isn't. Without this check, you could end up generating code that is incompatible with the runtime code contained in the framework.
148
+
The wrapper will call through to the included binaries and files that constitute the `apollo`command-line interface. This ensures that you can use our tooling without having to worry about NPM Version Hell™, and that the version of the framework you're using is compatible with the version of the codegen you're using.
149
149
150
150
The location of this wrapper script is slightly different based on how you've integrated Apollo into you project, but the first steps are the same everywhere:
151
151
152
152
1. On your application target's **Build Phases** settings tab, click the **+** icon and choose **New Run Script Phase**.
153
153
2. In the created Run Script, change its name to **Generate Apollo GraphQL API**
154
154
3. Drag this new run script just above **Compile Sources** in your list of **Build Phases** so that it executes before your code is compiled.
155
-
4. Add the appropriate contents to the run script from the options below.
155
+
4. Add the contents of the appropriate run script for the package manager you're using from this list:
Our CocoaPods install includes the code-generation script as a file which will not be added to the framework. Since this is always installed in a consistent place, you can use the same path to it. Add the following to the Run Script:
### If you are integrating Apollo using SPM + Xcode 11 [BETA]
168
-
169
-
> NOTE: These instructions are as of Xcode 11, beta 4. Please file an issue if anything has changed in newer betas or in the final release!
170
-
171
-
If you're using Xcode 11, SPM will check out the appropriate build script along with the rest of the files. Add the following to your Run Script build phase:
164
+
If you're using Xcode 11 or higher, SPM will check out the appropriate build script along with the rest of the files when it checks out the repo. Add the following to your Run Script build phase:
172
165
173
166
```sh
174
-
# Go to the build root and go back up to where SPM keeps the apollo iOS framework checked out.
167
+
# Go to the build root and go back up to where SPM keeps the Apollo iOS repo checked out.
> NOTE: If you try to use this with command line SPM, when you regenerate your `xcodeproj` this build script will get wiped out. We strongly recommend using Xcode 11's built-in SPM handling rather than the command line because of this.
190
183
191
-
### If you're NOT integrating Apollo using CocoaPods
192
-
193
-
In this case, the `check-and-run-apollo-cli.sh` file is bundled into the framework. The procedures to call it are slightly different based on whether you're using an iOS or macOS target because of the way the frameworks are compiled.
184
+
### CocoaPods Run Script
194
185
195
-
📱 For an **iOS** target or a **Cocoa Touch Framework**, add the following to your Run Script build phase:
186
+
Our CocoaPods install includes the code-generation scripts and binaries of the `apollo` CLI client as files which will not be added to the framework, but which you can still call from a Run Script Build Phase. Add the following to the Run Script:
196
187
197
188
```sh
198
-
# Do some magic so we can make sure `FRAMEWORK_SEARCH_PATHS` works correctly when there's a space in the scheme or the folder name.
199
-
QUOTED_FRAMEWORK_SEARCH_PATHS=\"$(echo $FRAMEWORK_SEARCH_PATHS| tr -d '"'| sed -e 's/ \//" "\//g')\"
echo"error: Couldn't find Apollo.framework in FRAMEWORK_SEARCH_PATHS; make sure to add the framework to your project."
206
-
exit 1
207
-
fi
196
+
In the never-ending battle of what's going to be more painful when it comes to dependency management, we've decided to make working with Carthage a bit more of a pain in order to make working with NPM way less of a pain.
The scripts and binaries which you need to generate code will be included in the `Carthage/Checkouts` folder. If this folder is not checked into version control, all developers on a team (and your CI machine) will need to run `carthage checkout` when changes are made to the version to ensure they have the correct underlying binaries and scripts.
212
199
213
-
💻 For a **macOS** or a **Cocoa Framework** target, add the following to your Run Script build phase:
200
+
Once everyone's on the same page about that, you should be able to use this build script:
214
201
215
202
```sh
216
-
# Do some magic so we can make sure `FRAMEWORK_SEARCH_PATHS` works correctly when there's a space in the scheme or the folder name.
217
-
QUOTED_FRAMEWORK_SEARCH_PATHS=\"$(echo $FRAMEWORK_SEARCH_PATHS| tr -d '"'| sed -e 's/ \//" "\//g')\"
echo"error: Couldn't find Apollo.framework in FRAMEWORK_SEARCH_PATHS; make sure to add the framework to your project."
224
-
exit 1
225
-
fi
210
+
You'll need to find the place where you've downloaded the Apollo iOS SDK, and manually set the `SCRIPT_PATH` to that folder. Usually this works best if it's related to `SRCROOT` so it's always the same
211
+
212
+
Replace `__YOUR_PATH_TO_THE_SCRIPT_FOLDER__` with (you guessed it) your path to the script folder in this script:
At this point, you can try building your target in Xcode. This will verify that the `schema.json` file can be found by the `apollo` script created above, and run the codegen.
0 commit comments