Swiftpack.co - joinhandshake/Querl as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by joinhandshake.
joinhandshake/Querl 0.2.0
A minimal GraphQL client library for iOS
⭐️ 15
🕓 49 weeks ago
iOS macOS
.package(url: "https://github.com/joinhandshake/Querl.git", from: "0.2.0")

Querl

CI Status Version License Platform

Querl is a minimal GraphQL client library. It aims to be agnostic as to the architecture and technology choices of your app. It can be used with any networking stack, and makes no assumptions about how your models are defined. In addition, it is as Swift-y as possible: protocol-oriented, type-safe, and chock full of generics. It has no dependencies, and comprises less than 200 lines of easily auditable code.

Querl is not a GraphQL query construction library. Rather than providing a framework or DSL to build queries at compile-time, Querl expects you to use your preferred testing tool (Paw, Postman, Graphiql, Insomnia, and so on) to generate a static .graphql file, which Querl reads from disk.

Features

Querl supports the following GraphQL features:

  • Single-model queries
  • Mutations
  • Paginated queries
  • Variables
  • Fragments
  • Type conditions
  • Directives
  • Aliasing

It supports those GraphQL features with these Swift language features:

  • Composable, extensible query protocols
  • Strongly-typed arguments and responses
  • Bring your own model types

Querl does not (yet) support the following GraphQL features:

  • Queries returning multiple top-level models
  • Subscriptions

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

The code can be as simple as this:

CountryForCode.graphql

query($code: ID!) {
    country(code: $code) {
        name
    }
}

main.swift

import Querl

struct CountryForCode: Query, HasArguments {
    struct Response: Decodable {
        let country: Country?
    }
    let code: String
}

let query = CountryForCode(code: "US")
let request = URLRequest(url: graphQLEndpoint)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try JSONSerialization.data(withJSONObject: query.body)
let (data, _) = try await URLSession.shared.data(for: request)
let country = try CountryForCode.decodeResponse(data).country // "United States of America"

This pattern can be easily adapted to Alamofire, or any other networking library that performs POST requests.

Requirements

Querl requires iOS 11.0 or higher.

Installation

CocoaPods

Querl is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Querl'

Swift Package Manager

Declare Querl as a package dependency.

.package(
    name: "Querl", 
    url: "https://github.com/joinhandshake/Querl", 
    .upToNextMinor(from: "0.1.0")),

Use Querl in target dependencies

.product(name: "Querl", package: "Querl")

Contributing

See CONTRIBUTING.md for more information. Contributions are welcome!

Code of Conduct

See CODE_OF_CONDUCT.md for more information.

Author

Joel Kin, [email protected], @[email protected]

License

Querl is available under the Apache 2.0 license. See the LICENSE file for more info.

GitHub

link
Stars: 15
Last commit: 46 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

0.2.0
49 weeks ago

What's Changed

New Contributors

Full Changelog: https://github.com/joinhandshake/Querl/compare/0.1.2...0.2.0

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