https://github.com/jottenlips/festivalschedule-watchapp
👩🎤 Configuring an Apollo GraphQL client for iOS paired with a WatchOS app (presentation code) ⌚️
https://github.com/jottenlips/festivalschedule-watchapp
apollo graphql ios swift watchos
Last synced: about 2 months ago
JSON representation
👩🎤 Configuring an Apollo GraphQL client for iOS paired with a WatchOS app (presentation code) ⌚️
- Host: GitHub
- URL: https://github.com/jottenlips/festivalschedule-watchapp
- Owner: jottenlips
- Created: 2019-02-23T21:39:20.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-07-12T16:24:34.000Z (almost 6 years ago)
- Last Synced: 2025-06-09T06:08:21.471Z (about 1 year ago)
- Topics: apollo, graphql, ios, swift, watchos
- Language: Swift
- Homepage:
- Size: 7.62 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Making a GraphQL iOS App with Apollo
## 📈💖🍏
*presentation code*
## Client Setup
**Install Apollo**
> `npm install -g apollo`
> `npm install -g apollo-codegen`
**Setup Project**
>- run `gem install cocoapods`
>- make a new iOS project
>- Add Apollo's GraphQL pod to your podfile
>- `cd newProjectName`
>- run `pod install`
**Grab schema from your endpoint**
>- In this case I will grab it from the production endpoint
>
> `
apollo schema:download --endpoint=https://api.aloompa.com/graphql schema.json`
>- get or make your .graphql file
>
> `touch queries.graphql`
>
> `vim queries.graphql`
>- ### 👩🏫 learn vim
```
query Performers($id: String!) {
festapp(id: $id) {
name
startsAt
events {
performers {
name
}
name
startsAt
}
}
}
```
>- Generate your api code 😮
>
>`apollo-codegen generate **/*.graphql --schema schema.json --output API.swift`
>- Add *queries.graphql and API.swift* to your xcodeworkspace
>- Apollo code to add to your class or delegate
```
import Apollo
var 👩🚀: ApolloClient {
return configureApollo()
}
func configureApollo() -> ApolloClient {
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = CONFIG_HEADERS;
let url = URL(string: "https://api.aloompa.com/graphql")!
let 👩🚀 = ApolloClient(networkTransport: HTTPNetworkTransport(url: url, configuration: configuration))
👩🚀.cacheKeyForObject = { $0["id"] }
return 👩🚀;
}
```
>- config.swift
```
let CONFIG_HEADERS = ["applicationtoken": "", "authorization": ""]
```
**Running GQL server locally** *(optional)*
> `cd ~/`
> `mkdir aloompaApis`
> `cd aloompaApis`
> `git clone git@github.com:Aloompa/aloompa-api-graphql.git`
> `git clone git@github.com:Aloompa/citizen-users-api.git`
> `git clone git@github.com:Aloompa/festapi-graphql.git`
> run `npm i` in all directories
> cd `aloompa-api-graphql`
> run `npm run start:local` or `python start.py`
> Should be running on **Port 9000**
## Why we are here
```
func loadData() {
let watcher = apollo.watch(query: PerformersQuery(id: someIdString)) { (result, error) in
if let error = error {
NSLog("Error while fetching query: \(error.localizedDescription)")
return
}
// some lazy global variable should do
self.festapp = result?.data?.festapp
}
}
```