DashX SDK for iOS
CocoaPods
Specify the dependency in your Podfile
:
pod 'DashX'
Run the following command:
pod install
Carthage
Specify the dependency in your Cartfile
:
github "dashxhq/dashx-ios"
Run the following command:
carthage update
Swift Package Manager
Add the following to your Package.swift
:
dependencies: [
.package(url: "https://github.com/dashxhq/dashx-ios.git", .upToNextMajor(from: "1.0.0"))
]
For detailed usage, refer to the documentation.
- Make sure to install Apollo CLI and GraphQL.js via npm:
$ npm i -g apollo
$ npm i -g graphql
- In order to generate code, Apollo requires local copy of Graphql schema, to download that:
$ apollo schema:download --endpoint="https://api.dashx-staging.com/graphql" schema.json
This will save a schema.json
file in your ios directory.
-
Add Graphql request in
graphql
dir. -
Regenerate
API.swift
using:
$ apollo client:codegen --target=swift --namespace=DashXGql --localSchemaFile=schema.json --includes="Graphql/*.graphql" --passthroughCustomScalars Sources/DashX/API.swift
For example, if you want to generate code for FetchCart
.
- Download schema
$ apollo schema:download --endpoint="https://api.dashx-staging.com/graphql" schema.json
- Add request in
graphql
dir with following contents:
query FetchCart($input: FetchCartInput!) {
fetchCart(input: $input) {
id
// ... other fields
}
}
- Re-generate API.swift so it includes the
FetchCart
operation
$ apollo client:codegen --target=swift --namespace=DashXGql --localSchemaFile=schema.json --includes="Graphql/*.graphql" --passthroughCustomScalars Sources/DashX/API.swift
- Now you can use FetchCart operation like so:
let fetchCartInput = DashXGql.FetchCartInput( // Note the DashXGql namespace
accountUid: self.accountUid,
accountAnonymousUid: self.accountAnonymousUid
)
DashXLog.d(tag: #function, "Calling fetchCart with \(fetchCartInput)")
let fetchCartQuery = DashXGql.FetchCartQuery(input: fetchCartInput)
Network.shared.apollo.fetch(query: fetchCartQuery) { result in
switch result {
case .success(let graphQLResult):
let json = graphQLResult.data?.fetchCart
DashXLog.i(tag: #function, "Sent fetchCart with \(String(describing: json))")
successCallback(json?.resultMap)
case .failure(let error):
DashXLog.e(tag: #function, "Encountered an error during fetchCart(): \(error)")
failureCallback(error)
}
}
- Compile package
NOTE: platforms
key in Package.swift
only specifies the minimum supported version for ex: .iOS(...)
.
To restrict the compilation to only one platform, either set the destination in Xcode to Any iOS Device
or use the following command
$ xcodebuild -scheme DashX -destination 'generic/platform=iOS'
instead of
$ swift build
- Bump up the version number in
DashX.podspec
andSources/DashX/Constants.swift
- Commit the version bump:
Bump version to x.x.x
- Create a tag:
git tag 'x.x.x'
- Push the tag:
git push origin --tags
The GitHub Workflow will take care of the rest.