Replies: 1 comment 3 replies
-
Looks good to me. Maybe name it It's possible to do something like: protocol Queriable {
associatedtype T
init(fields: Fields<T>)
}
extension Queriable {
static var selection: Selection<Self, T> {
.init(decoder: Self.init(fields:))
}
} Which would have the same behaviour as your initial example but you'd write your selection as the init. Or do you want to change the HTTP methods to accept the Queriable rather than a Selection? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
API
One of the most common ways for us to construct a query for a particular type is to add a static method
selection
to a particular structure.This seemed like a very clean solution and it did the job well. Now as the library evolves it seems better to extract this pattern into a more Swift-native concept. My idea here is that we add a protocol (e.g.
Queriable
) that requires an initialiser that takes aField<TypeLock>
type as an input and initialised the current type. Once a structure conforms to theQueriable
protocol you can use it in the queries.I think this makes a lot of sense since the new API would highly resemble the decoder API that Swift has built in.
Syntactic Sugars
I love how we implemented the
Selection.Human
type alias. They let us have much better IDE integration and I think we should do the same thing withFields.Human
.Legacy
It might seem like we should replace the
Selection.Human
API entirely in favour of the new initialisers API. I don't think that's a good idea. Instead, we should aim to makeSelection.Human
by default conform toQueriable
and have the two APIs interchangeable.Beta Was this translation helpful? Give feedback.
All reactions