GraphQLSwift / Graphiti

The Swift GraphQL Schema framework for macOS and Linux
MIT License
531 stars 67 forks source link

Renaming ConnectionTypes isn't working #106

Closed cshadek closed 1 year ago

cshadek commented 1 year ago

Renaming connection types, doesn't seem to fully work.

Type(ChatObject.self, as: "Chat") {
    Field("messages", at: ChatObject.messages, as: Connection<MessageObject>.self) {
                    Argument("first", at: \.first)
                    Argument("after", at: \.after)
                    Argument("last", at: \.last)
                    Argument("before", at: \.before)
    }
}

Type(MessageObject.self, as: "Message") {
    Field("id", at: \.id)
    Field("text", at: \.text)
}

ConnectionType(MessageObject.self, as: "Message")

I get the following error: Fatal error: 'try!' expression unexpectedly raised an error: Type "MessageObjectConnection" was referenced but not defined.

When I don't rename the ConnectionType, then the schema builds, but I end up with MessageObjectConnection instead of MessageConnection.

If I don't include the Chat type, then the schema builds with the correct MessageConnection name.

cshadek commented 1 year ago

@d-exclaimation do you have an idea of how to fix this?

d-exclaimation commented 1 year ago

Not 100% sure what's the issue is caused by. My guess is probably the fact the Message Object Connection is referenced in Chat type and renaming it somehow breaks that. I haven't used it personally in a while but I can take a look at it

cshadek commented 1 year ago

While on this topic, there's probably some sense in rethinking the Connection API sometime.

Some nice improvements would be:

These improvements would arguably make the Connection feature that much more powerful.

I have a bit of an idea of how this could be done, but my understanding is that there are issues around how to make this work with Codable.

cshadek commented 1 year ago

@d-exclaimation the renaming issue is obviously more pressing (though it's still not the end of the world), but I thought you may have some ideas on everything else too.

And there's always the ability to just create your own custom connections, and that solves all these problems

cshadek commented 1 year ago

The main issue is fixed as of #109.

cshadek commented 1 year ago

Since the main issue is fixed, I created a new issue #110 to discuss other improvements to connections that were mentioned above.