PersistQL是Swift中基于Projection的GraphQL客户端和服务器
PersistQL是Swift中基于Projection的GraphQL客户端和服务器
Swift 其它杂项
共70Star
详细介绍
✊
📡
PersistQL
Projection-based GraphQL Clients and Servers in Swift
PersistQL is alpha-quality software. It currently has a number of limitations.
GraphQL makes APIs much more flexible. Instead of hardcoding endpoints that return specific data, GraphQL lets clients decide which relationships and properties are returned. But how can this information be encoded in the type system in a way that retains flexibility but maintains type safety?
PersistQL tries to answer this by describing GraphQL schemas in the type system and letting clients project these schemas onto their own types to create requests.
// A description of the GraphQL schema
final class Book {
struct ISBN {
let string: String
}
let id: ISBN
let title: String
let author: Author
}
extension Book: Model {
static let schema = Schema(
Book.init,
\.id ~ "isbn",
\.title ~ "title",
\.author ~ "author"
)
}
final class Author {
let id: UUID
let name: String
let books: Set<Book>
}
extension Author: Model {
static let schema = Schema(
Author.init,
\.id ~ "id",
\.name ~ "name",
\.books ~ "books"
)
}
// A local view model, which is projected from the schema
// It can be used to create a GraphQL query
struct BookViewModel {
let isbn: ISBN
let title: String
let author: String
}
extension BookViewModel: ModelProjection {
static let projection = Projection<Book, BookViewModel>(
BookViewModel.init,
\.id,
\.title,
\.author.name
)
}
License
PersistQL is available under the MIT license.
-
0 Star
-
123 Star
-
448 Star
-
2591 Star
-
1159 Star
-
192 Star
-
895 Star
-
2001 Star