Swift Package Index


Write GraphQL queries like SwiftUI views - no strings, no dictionaries.


  • The latest stable release is 0.0.1. Released over 1 year ago.
  • The last commit to master was 6 months ago.

Swift Version Compatibility

  • 0.0.1 and master
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • 0.0.1 and master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

Artemis

Note that Artemis is not yet considered suitable for production development due to the unstable nature of Swift's 'function builders', whose internal implementation changes greatly between Xcode versions. Until this Swift feature is officially implemented, Artemis can break between Xcode versions and should be considered 'beta'. Currently, Artemis builds with Swift 5.3 (which is included with the latest Xcode 12 beta!)

Artemis is a GraphQL library for Swift that lets you interact with a GraphQL backend entirely in Swift - no unsafe queries made of strings, no Data or [String: Any] responses you need to parse though manually. Artemis uses KeyPath objects to keep track of types used in queries, so this request:

// Artemis                                  // Rendered GraphQL query
Operation(.query) {                         query {
    Add(\.country, alias: "canada") {           canada: country(code: "CA") {
        Add(\.name)                                 name
        Add(\.continent) {                          continent {
            Add(\.name)                                 name
        }                                           }
    }.code("CA")                                }
}                                           }

...results in a Partial<Country> object that you can interact with using the same keypaths and type inference as a normal Country instance. Artemis will populate the response object with the fetched data - so this query (and its response) are handled like this:

let client = Client<Query>()

client.perform(query) { result in
    switch result {
    case .success(let country):
        country.name // "Canada"
        country.continent?.name // "North America"
        country.languages // nil
    case .failure(let error):
        // error handling
    }
}

Don't let this simple example sell Artemis short, though - it includes full support for fragments, arguments, mutations, multiple query fields, and code generation from GraphQL schema documents so you can get up and running with a new API in minutes. It's also very light (requiring only Foundation), so supports iOS, macOS, or anywhere else Swift and Foundation can run.

For instructions on adding Artemis to your project and setting up code generation, check out the installation and setup guide.

Once you're setup, you can check out the tutorial on getting started with Artemis guide to get up and running with making requests.

Contributors

Aaron Bosnjak (email: aaron.bosnjak707@gmail.com, Twitter: @aaron_bosnjak)

Artemis is open to contributors! If you have a feature idea or a bug fix, feel free to open a pull request. Issues and feature ideas are tracked on this Trello board.

License

Artemis is available under the MIT license, so do pretty much anything you want with it. As always, see the LICENSE file for more info.