Skip to content

Latest commit

 

History

History

quickstart-with-apollo

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

iOS & Apollo Quickstart

  • Apollo Client: Fully-featured, production ready caching GraphQL client
  • Graphcool: Flexible backend platform combining GraphQL + AWS Lambda

For more information on how to get started refer to the full ios-apollo-instagram tutorial.

Example

Quickstart

1. Clone example repository

git clone https://github.com/graphcool-examples/ios-graphql.git
cd ios-graphql/quickstart-with-apollo

2. Create Graphcool service with the Graphcool CLI

# Install Graphcool Framework CLI
npm install -g graphcool

# Create a new service inside a directory called `server`
graphcool init server

This created the following file structure in the current directory:

.
└── server
    ├── graphcool.yml
    ├── types.graphql
    └── src
        ├── hello.graphql
        └── hello.js

3. Define data model

Next, you need to define your data model inside the newly created types.graphql-file.

Replace the current contents in types.graphql with the following type definition (you can delete the predefined User type):

type Post @model {
  # Required system field
  id: ID! @isUnique # read-only (managed by Graphcool)

  # Optional system fields (remove if not needed)
  createdAt: DateTime! # read-only (managed by Graphcool)
  updatedAt: DateTime! # read-only (managed by Graphcool)

  description: String!
  imageUrl: String!
}

4. Deploy the GraphQL server

You're now ready to put your Graphcool service into production! Navigate into the server directory and deploy the service:

cd server
graphcool deploy

Save the HTTP endpoint for the Simple API from the output, you'll need it in the next step.

Note: You can now test your GraphQL API inside a GraphQL playground. Simply type the graphcool playground command and start sending queries and mutations.

5. Connect the app with your GraphQL API

Paste the Simple API endpoint into AppDelegate.swift to instantiate the ApolloClient:

// replace `__SIMPLE_API_ENDPOINT__` with the endpoint from the previous step
let apollo = ApolloClient(url: URL(string: "__SIMPLE_API_ENDPOINT__")!)

6. Install apollo-codegen

To use the Apollo iOS Client, you need to install apollo-codegen, a command line tool that will generate Swift types from your GraphQL queries & mutations at build-time.

npm install -g apollo-codegen

You can find more info the installation process in the Apollo docs.

7. Install dependencies & run locally

cd ..
carthage update

Start the app in Xcode 🚀

Next steps

Help & Community Slack Status

Join our Slack community if you run into issues or have questions. We love talking to you!