Skip to content
Visual debugger for Apollo iOS GraphQL client
Swift TypeScript Ruby Objective-C HTML JavaScript CSS
Branch: master
Clone or download
manicmaniac Merge pull request #51 from manicmaniac/fix-variable-name-to-event-st…
…ream-queue-map

s/eventStreamQueue/eventStreamQueueMap/g
Latest commit 1546c3d Aug 23, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ApolloDeveloperKit.xcodeproj Add tests for NetworkInterface Aug 21, 2019
Example Add button to show IP address on example app Aug 18, 2019
Sources s/eventStreamQueue/eventStreamQueueMap/g Aug 23, 2019
Tests Add tests for NetworkInterface Aug 21, 2019
docs Update API reference Aug 21, 2019
src set application/json content type when sending request Jun 30, 2019
.codeclimate.yml exclude docs/ folder from linter Jul 14, 2019
.gitattributes Treat generated files as binary Aug 21, 2019
.gitignore ignore Carthage/Checkouts Aug 18, 2019
.swiftlint.yml exclude docs/ folder from linter Jul 14, 2019
.travis.yml add matrix for CI Jul 18, 2019
ApolloDeveloperKit.podspec bump version to 0.3.2 Aug 21, 2019
Cartfile loosen version specification of Apollo Jul 18, 2019
Cartfile.private loosen version specification of Apollo Jul 18, 2019
Cartfile.resolved remove GCDWebServer from dependencies Jul 12, 2019
LICENSE Initial commit Jun 16, 2019
README.md
package-lock.json bump version to 0.3.2 Aug 21, 2019
package.json
tsconfig.json enable es2015 modules Jul 12, 2019
webpack.config.js add npm run dist command to run production build Jul 12, 2019

README.md

ApolloDeveloperKit

Build Status Maintainability CocoaPods Compatible Carthage Compatible Platform

Apollo Client Devtools bridge for Apollo iOS.

Overview

ApolloDeveloperKit is an iOS library which works as a bridge between Apollo iOS client and Apollo Client Developer tools.

This library adds an ability to watch the sent queries or mutations simultaneously, and also has the feature to request arbitrary operations from embedded GraphiQL console.

Screenshots

apollo-developer-kit-animation

Prerequisites

Installation

Install from Carthage

Add the following lines to your Cartfile.

github "apollographql/apollo-ios"
github "manicmaniac/ApolloDeveloperKit"

Then run carthage update --platform iOS.

Install from CocoaPods

Add the following lines to your Podfile.

pod 'Apollo'
pod 'ApolloDeveloperKit'

Then run pod install.

Setup

First, in order to hook Apollo's cache and network layer, you need to use DebuggableNetworkTransport and DebuggableInMemoryNormalizedCache instead of usual ones.

let networkTransport = DebuggableNetworkTransport(networkTransport: HTTPNetworkTransport(url: url))
let cache = DebuggableInMemoryNormalizedCache()

Second, instantiate ApolloStore and ApolloClient with debuggable ingredients.

let store = ApolloStore(cache: cache)
let client = ApolloClient(networkTransport: networkTransport: store: store)

Finally, create ApolloDebugServer and run.

let debugServer = ApolloDebugServer(cache: cache, networkTransport: networkTransport)
self.debugServer = debugServer // Note: you need to retain debugServer's reference
debugServer.start(port: 8081)

Full example:

import Apollo
import ApolloDeveloperKit
import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    private var client: ApolloClient!
    private var debugServer: ApolloDebugServer?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        let url = URL(string: "https://example.com/graphql")!
        #if DEBUG
            let networkTransport = DebuggableNetworkTransport(networkTransport: HTTPNetworkTransport(url: url))
            let cache = DebuggableNormalizedCache(cache: InMemoryNormalizedCache())
            let store = ApolloStore(cache: cache)
            client = ApolloClient(networkTransport: networkTransport, store: store)
            debugServer = ApolloDebugServer(networkTransport: networkTransport, cache: cache)
            do {
                try debugServer.start(port: 8081)
            } catch let error {
                print(error)
            }
        #else
            client = ApolloClient(url: url)
        #endif
        return true
    }
}

Excluding ApolloDeveloperKit from Release (App Store) Builds

All instructions in this section are written based on Flipboard/FLEX's way.

Since ApolloDeveloperKit is originally designed for debug use only, it should not be exposed to end-users.

Fortunately, it is easy to exclude ApolloDeveloperKit framework from Release builds. The strategies differ depending on how you integrated it in your project, and are described below.

Please make sure your code is properly excluding ApolloDeveloperKit with #if DEBUG statements before starting these instructions. Otherwise it will be linked to your app unexpectedly. See Example/AppDelegate.swift to see how to do it.

For CocoaPods users

CocoaPods automatically excludes ApolloDeveloperKit from release builds if you only specify the Debug configuration for CocoaPods in your Podfile.

For Carthage users

  1. Do NOT add ApolloDeveloperKit.framework to the embedded binaries of your target, as it would otherwise be included in all builds (therefore also in release ones).
  2. Instead, add $(PROJECT_DIR)/Carthage/Build/iOS to your target Framework Search Paths (this setting might already be present if you already included other frameworks with Carthage). This makes it possible to import the ApolloDeveloperKit framework from your source files. It does not harm if this setting is added for all configurations, but it should at least be added for the debug one.
  3. Add a Run Script Phase to your target (inserting it alter the existing Link Binary with Libraries phase, for example), and which will embed ApolloDeveloperKit.framework in debug builds only:
if [ "$CONFIGURATION" == "Debug" ]; then
  /usr/local/bin/carthage copy-frameworks
fi

Finally, add $(SRCROOT)/Carthage/Build/iOS/ApolloDeveloperKit.framework as input file of this script phase.

For users those who copy all the source files to the project manually

Now there's no easy way but you can exclude ApolloDeveloperKit by setting user defined build variable named EXCLUDED_SOURCE_FILE_NAMES. The value for the variable is a space-separated list of each filenames in ApolloDeveloperKit. Sorry for the inconvenience.

Usage

Open browser after launching Simulator and jump to http://localhost:8081 (or other specified port) on your Chrome. Then open developer tools and select Apollo tab.

Development

API Documentation

Auto-generated API documentation is here.

Run Example App

Since Example app is slightly modified version of apollographql/frontpage-ios-app, you need to start apollographql/frontpage-server before runnning the app.

  1. Open Xcode and select ApolloDeveloperKitExample scheme.
  2. Run and open http://localhost:8081 in Google Chrome.

License

This software is distributed under the MIT license. See LICENSE for more detail.

You can’t perform that action at this time.