Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore dynamicMemberLookup and dynamicCallable to make code simpler #11

Open
nerdsupremacist opened this issue Apr 20, 2020 · 1 comment
Labels
Client API Refers to an issue in the API code generated by Graphaello Generation Refers to how the Swift Code is generated

Comments

@nerdsupremacist
Copy link
Owner

nerdsupremacist commented Apr 20, 2020

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

@nerdsupremacist nerdsupremacist changed the title Explore Explore dynamicMemberLookup and dynamicCallable to make code simpler Apr 20, 2020
@nerdsupremacist nerdsupremacist added Client API Refers to an issue in the API code generated by Graphaello Generation Refers to how the Swift Code is generated labels Apr 24, 2020
@nerdsupremacist
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client API Refers to an issue in the API code generated by Graphaello Generation Refers to how the Swift Code is generated
Projects
Development

No branches or pull requests

1 participant