Skip to content

Instantly share code, notes, and snippets.

@emarashliev
Last active March 6, 2018 17:26
Show Gist options
  • Save emarashliev/02e0ed6676910b69c360d3d6e1346ac1 to your computer and use it in GitHub Desktop.
Save emarashliev/02e0ed6676910b69c360d3d6e1346ac1 to your computer and use it in GitHub Desktop.
Apollo with SQLite
import Apollo
let path = NSSearchPathForDirectoriesInDomains( .documentDirectory, .userDomainMask, true).first!
let url = URL(string: "http://localhost:3000/graphql")!
let cache = try! SQLiteNormalizedCache(fileURL: URL(string: "\(path)/db.sqlite3")!)
let apollo = ApolloClient(networkTransport: HTTPNetworkTransport(url: url), store: ApolloStore(cache: cache))
apollo.fetch(query: AllReceiptsQuery()){ (result, error) in
print(result?.data?.receipts?.first)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment