Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Saelyria/Artemis
Write GraphQL queries like SwiftUI views - no strings, no dictionaries.
https://github.com/Saelyria/Artemis
artemis function-builder graphql ios macos result-builder swift
Last synced: about 1 month ago
JSON representation
Write GraphQL queries like SwiftUI views - no strings, no dictionaries.
- Host: GitHub
- URL: https://github.com/Saelyria/Artemis
- Owner: Saelyria
- License: mit
- Created: 2019-06-16T02:21:54.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-09-12T22:27:20.000Z (about 2 years ago)
- Last Synced: 2024-07-24T15:02:22.537Z (5 months ago)
- Topics: artemis, function-builder, graphql, ios, macos, result-builder, swift
- Language: Swift
- Homepage:
- Size: 603 KB
- Stars: 63
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-result-builders - Artemis - Interact with GraphQL in Swift - not strings (GraphQL)
README
# Artemis
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:```swift
// 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` 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:```swift
let client = Client()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:```swift
// 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](https://github.com/Saelyria/Artemis/tree/master/GettingStarted.md)
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](https://trello.com/b/iDjeDfov/artemis).## 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.