A NetworkTransport
implementation for using Phoenix + Absinthe with Apollo's Swift library.
Warning: This library is experimental, and developed by a beginner in Swift. Contributions are welcome.
- You use the Absinthe GraphQL implementation for the Elixir language
- You expose Absinthe in a Phoenix app using Absinthe.Phoenix
- You use websockets (via Phoenix channels) to run GraphQL subscriptions (and optionally regular queries + mutations)
- You wish to connect to this GraphQL server from a Swift application using Apollo iOS (which also serves macOS, etc.)
The Apollo iOS library uses NetworkTransport
s to implement sending/receiving GraphQL operations. This package provides AbsintheSocketTransport
, an implementation of NetworkTransport
that communicates via websockets in a Phoenix/Absinthe-friendly way. Use this library if you would prefer not to modify the server using something like absinthe_apollo_sockets.
This package was created using Swift Package Manager. If you require the use of a different package manager, please help me to implement any requirements.
.package(url: "https://github.com/aj-foster/absinthe-socket-transport.git", .upToNextMinor(from: "0.0.1"))
Note that this package has fairly strict version dependencies on SwiftPhoenixClient
and Apollo
. If you require the use of different versions, please help me to test those packages.
To use this package, add the following import statement:
import AbsintheSocketTransport
Then, use the AbsintheSocketTransport
class as a NetworkTransport
when setting up the client:
let transport = AbsintheSocketTransport(endpoint, params: ["token": token])
let client = ApolloClient(networkTransport: transport, store: ApolloStore.init())
Although untested, this transport might also work as part of a SplitNetworkTransport
.
For debugging purposes, you can enable a printout of all socket messages (including keepalives):
transport.enableDebug()
As noted above, contributions are welcome. If you propose code changes, please help by also explaining any relevant best practices and including links to documentation where appropriate. For more information, please see the contribution guidelines.