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
shellScript = "# 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.\nQUOTED_FRAMEWORK_SEARCH_PATHS=\\\"$(echo $FRAMEWORK_SEARCH_PATHS | tr -d '\"' | sed -e 's/ \\//\" \"\\//g')\\\"\n\n# Get the first result searching for the framework\nAPOLLO_FRAMEWORK_PATH=\"$(eval find ${QUOTED_FRAMEWORK_SEARCH_PATHS} -name \"Apollo.framework\" -maxdepth 1 -print | head -n 1)\"\n\nif [ -z \"${APOLLO_FRAMEWORK_PATH}\" ]; then\n echo \"error: Couldn't find Apollo.framework in FRAMEWORK_SEARCH_PATHS; make sure to add the framework to your project.\"\n exit 1\nfi\n\ncd ${SRCROOT}/Tests/StarWarsAPI\nif [[ $SDK_NAME == *\"macos\"* ]]; then\n # Run the mac script\n\"${APOLLO_FRAMEWORK_PATH}\"/Versions/Current/Resources/check-and-run-apollo-cli.sh codegen:generate --target=swift --localSchemaFile=\"schema.json\" --includes=./**/*.graphql --mergeInFieldsFromFragmentSpreads API.swift\nelse\n # run the non-mac script\n\"${APOLLO_FRAMEWORK_PATH}\"/check-and-run-apollo-cli.sh codegen:generate --target=swift --localSchemaFile=\"schema.json\" --includes=./**/*.graphql --mergeInFieldsFromFragmentSpreads API.swift\nfi\n";
Copy file name to clipboardExpand all lines: docs/source/installation.md
+59-61Lines changed: 59 additions & 61 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,9 +16,29 @@ 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 CocoaPods, Carthage, or by manually integrating it with Xcode.
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
-
### CocoaPods
21
+
### Swift Package Manager Installation
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)
24
+
25
+
1. Go to **File > Swift Packages > Add Package Dependency... **
26
+
27
+

28
+
29
+
1. Paste the URL to the Apollo iOS repo on GitHub into the search bar, then hit the **Next** button:
30
+
31
+

32
+
33
+
1. Select what version you want to use, then hit next. Xcode will automatically suggest the current version `Up to Next Major`, we **strongly** suggest that while the iOS SDK is on a `0.x.x` version scheme, you select `Up To Next Minor` instead, as we will still be releasing breaking changes on minor versions:
34
+
35
+

36
+
37
+
1. Select which packages you want to use. If you're just getting started, try selecting just the main `Apollo` library first - you can always come back and add the other packages later if you need them. Then hit finish.
38
+
39
+

40
+
41
+
### CocoaPods Installation
22
42
23
43
1. Because Apollo iOS has been written using Swift 5, you need to use version `1.7.0` or higher. You can install CocoaPods using:
24
44
@@ -34,7 +54,7 @@ You can install `Apollo.framework` into your project using CocoaPods, Carthage,
34
54
35
55
1. Use the `.xcworkspace` file generated by CocoaPods to work on your project.
36
56
37
-
### Carthage
57
+
### Carthage Installation
38
58
39
59
Since Carthage [does not allow choosing which schemes in a repo to build](https://github.com/Carthage/Carthage/issues/1874), we've moved our dependencies to a [`Cartfile.private`](https://github.com/apollographql/apollo-ios/blob/master/Cartfile.private) file so that those dependencies are not forced on people using only the `Apollo` framework and not either of our optional frameworks, `ApolloSQLite` or `ApolloWebSocket`.
40
60
@@ -66,7 +86,7 @@ This makes setup a hair more complicated if you *are* using those, but is a big
66
86
67
87
This script works around an [App Store submission bug](http://www.openradar.me/radar?id=6409498411401216) triggered by universal binaries and ensures that necessary bitcode-related files and dSYMs are copied when archiving.
68
88
69
-
### Manual integration
89
+
### Manual Integration
70
90
71
91
You can also manually clone the [`apollo-ios` repository](https://github.com/apollostack/apollo-ios), drag `Apollo.xcodeproj` into your project or workspace, add a dependency on `Apollo.framework` to your target.
72
92
@@ -123,35 +143,28 @@ If you have the Xcode add-ons installed, you can use the Xcode companion view to
123
143
124
144
## Adding a code generation build step
125
145
126
-
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.
127
147
128
-
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.
129
149
130
-
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:
150
+
The location of this wrapper script is slightly different based on how you've integrated Apollo into your project, but the first steps are the same everywhere:
131
151
132
152
1. On your application target's **Build Phases** settings tab, click the **+** icon and choose **New Run Script Phase**.
133
153
2. In the created Run Script, change its name to **Generate Apollo GraphQL API**
134
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.
135
-
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]
148
-
149
-
> 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!
150
-
151
-
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:
152
165
153
166
```sh
154
-
# 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.
170
183
171
-
### If you're NOT integrating Apollo using CocoaPods
172
-
173
-
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
174
185
175
-
📱 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:
176
187
177
188
```sh
178
-
# 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.
179
-
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."
186
-
exit 1
187
-
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.
192
199
193
-
💻 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:
194
201
195
202
```sh
196
-
# 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.
197
-
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."
204
-
exit 1
205
-
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
206
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.
214
224
215
225
### Troubleshooting
216
226
217
-
If you've installed `apollo` globally with NPM and the script still seems to be having trouble finding it, add the following to the beginning of your Run Script Build Phase:
218
-
219
-
```bash
220
-
source~/.bash_profile
221
-
```
222
-
223
227
If you get this error:
224
228
225
229
> Cannot find GraphQL schema file [...]
@@ -230,13 +234,7 @@ If you get this error:
230
234
231
235
> No operations or fragments found to generate code for.
232
236
233
-
If you don't have any `.graphql` files in your build tree, and you need to create at least `.graphql` file with a valid query.
234
-
235
-
If you get this error:
236
-
237
-
> Ensure that there is only one instance of "graphql" in the node_modules directory. If different versions of "graphql" are the dependencies of other relied on modules, use "resolutions" to ensure only one version is installed.
238
-
239
-
Delete the `node_modules` folder in your source root and rebuild.
237
+
If you don't have any `.graphql` files in your build tree, and you need to create at least `.graphql` file with a valid query. If you need to validate the structure of your query, please use [the GraphQL Formatter tool](http://toolbox.sangria-graphql.org/format).
0 commit comments