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.
$ npm i -g apollo
$ apollo schema:download --endpoint="https://api.dashx.com/graphql" schema.json
This will save a schama.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 API.swift
For example, if you want to generate code for FetchCart
.
$ apollo schema:download --endpoint="https://api.dashx.com/graphql" schema.json
graphql
dir with following contents:query FetchCart($input: FetchCartInput!) {
fetchCart(input: $input) {
id
// ... other fields
}
}
FetchCart
operation$ apollo client:codegen --target=swift --namespace=DashXGql --localSchemaFile=schema.json --includes="graphql/*.graphql" --passthroughCustomScalars API.swift
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)
}
}
DashX.podspec
and DashX\Constants.swift
Bump version to x.x.x
git tag 'x.x.x'
git push origin --tags
The GitHub Workflow will take care of the rest.
link |
Stars: 0 |
Last commit: 4 days ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics