Graphaello
Graphaello copied to clipboard
Explore dynamicMemberLookup and dynamicCallable to make code simpler
Something like this:
@dynamicMemberLookup
protocol Type: Target { }
extension Type {
// make member key paths static for the type
static subscript<T>(dynamicMember keyPath: KeyPath<GraphQLFragmentPath<Self, Self>, GraphQLFragmentPath<Self, T>>) -> GraphQLFragmentPath<Self, T> {
return .init()
}
static subscript<T>(dynamicMember keyPath: KeyPath<GraphQLFragmentPath<Self, Self>, GraphQLPath<Self, T>>) -> GraphQLPath<Self, T> {
return .init()
}
}
@dynamicMemberLookup
struct GraphQLFragmentPath<TargetType: Target, UnderlyingType> {
fileprivate init() {}
// nested values inside arrays
subscript<Value, Output>(dynamicMember _: KeyPath<GraphQLFragmentPath<TargetType, Value>, GraphQLPath<TargetType, Output>>) -> GraphQLPath<TargetType, [Output]> where UnderlyingType == [Value] {
return .init()
}
subscript<Value, Output>(dynamicMember _: KeyPath<GraphQLFragmentPath<TargetType, Value>, GraphQLPath<TargetType, Output>>) -> GraphQLPath<TargetType, [Output]?> where UnderlyingType == [Value]? {
return .init()
}
subscript<Value, Output>(dynamicMember _: KeyPath<GraphQLFragmentPath<TargetType, Value>, GraphQLFragmentPath<TargetType, Output>>) -> GraphQLPath<TargetType, [Output]> where UnderlyingType == [Value] {
return .init()
}
subscript<Value, Output>(dynamicMember _: KeyPath<GraphQLFragmentPath<TargetType, Value>, GraphQLFragmentPath<TargetType, Output>>) -> GraphQLPath<TargetType, [Output]?> where UnderlyingType == [Value]? {
return .init()
}
}
and similar strategies for dealing with optionals...
The main reason this is not being used right now is the fact that autocomplete is broken. We should evaluate if there's a way to have autocomplete working and still bringing the amount of code waaaay down
If this manages to work, we could get rid of _forEach and while we're at it I would also get rid of _fragment, since we probably can make it work somehow else