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


Build status Platform iOS Swift 5.3 compatible License: MIT

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 various Swift features to keep track of types used in queries, so this request:

// Artemis                                              // Rendered GraphQL query   
.query {                                                query {   
    $ .init(code: "CA")) {              country(code: "CA") {       
        $                                                 name
        $0.continent {                                          continent {
            $ "continentName")                         continentName: name
        }                                                       }
    }                                                       }
}                                                       } entirely type-checked - we can't add fields not on our schema, put fields in the wrong place, pass invalid arguments, or pass invalid types for our arguments.

Performing that query 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): // "Canada"
        country.continent?.name(alias: "continentName") // "North America"
        country.languages // nil
    case .failure(let error):
        // error handling

The schema representation in Swift is also very readable and maintains a reasonably close resemblance to the GraphQL schema syntax. A schema for the above query might look something like this:

// Artemis                                          // Original GraphQL schema
final class Query: Object {                         type Query {
    @Field("country")                                   country(code: String!): Country!
    var country: (Country, CountryArgs.Type)        }
    struct CountryArgs: ArgumentsList {             type Country {
        var code: String                                name: String!
    }                                                   languages: [String!]!
}                                                       continent: Continent!
final class Country: Object {                    
    @Field("name")                                  type Continent {
    var name: String                                    name: String!
    var languages: [String]

    var continent: Continent

final class Continent: Object {
    var name: String

Don't let this simple example sell Artemis short, though - it includes full support for fragments, arguments, interfaces, inputs, aliases, mutations, and multiple query fields. It's also very light (requiring only Foundation), so supports iOS, macOS, or anywhere else Swift and Foundation can run.

Artemis can be added to any project using Swift Package Manager.

Once you have it added to a project, you can check out the tutorial on getting started with Artemis guide to get up and running with making requests.


Aaron Bosnjak (email:, 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.


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.


  • Swift Tools 5.1.0
View More Packages from this Author


  • None
Last updated: Thu Mar 16 2023 17:45:13 GMT-0500 (GMT-05:00)