Swiftpack.co - dashxhq/dashx-ios as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by dashxhq.
dashxhq/dashx-ios 1.0.7
DashX SDK for iOS
⭐️ 0
🕓 11 weeks ago
iOS
.package(url: "https://github.com/dashxhq/dashx-ios.git", from: "1.0.7")


DashX

Your All-in-One Product Stack


dashx-ios

DashX SDK for iOS

Install

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"))
]

Usage

For detailed usage, refer to the documentation.

Contributing

Obtaining GraphQL schema and generating GraphQL operation

  • Make sure to install Apollo CLI via npm:
$ npm i -g apollo
  • In order to generate code, Apollo requires local copy of Graphql schema, to download that:
$ 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.

  • Download schema
$ apollo schema:download --endpoint="https://api.dashx.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 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)
  }
}

Publishing

  1. Bump up the version number in DashX.podspec and DashX\Constants.swift
  2. Commit the version bump: Bump version to x.x.x
  3. Create a tag: git tag 'x.x.x'
  4. Push the tag: git push origin --tags

The GitHub Workflow will take care of the rest.

GitHub

link
Stars: 0
Last commit: 4 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics