Giter VIP home page Giter VIP logo

artemis's Introduction

Artemis

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 {   
    $0.country(arguments: .init(code: "CA")) {              country(code: "CA") {       
        $0.name                                                 name
        $0.continent {                                          continent {
            $0.name(alias: "continentName")                         continentName: name
        }                                                       }
    }                                                       }
}                                                       }

...is 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):
        country.name // "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!
                                                    }
    @Field("languages")
    var languages: [String]

    @Field("continent")
    var continent: Continent
}

final class Continent: Object {
    @Field("name")
    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.

Contributors

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

artemis's People

Contributors

saelyria avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

artemis's Issues

Setup Cannot Find - graphql file

./Artemis-Generate --input "$PROJECT_DIR"/star.graphql --output "$PROJECT_DIR"/Models

I add the above common in my build phases, add added star.graphql file to my project.

but the following error is produced, on Xcode 11.4 project

Artemis-Generate[60233:3725847] Fatal error: No path to the schema file was specified: file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.