-
Notifications
You must be signed in to change notification settings - Fork 67
Drops Encodable requirement on GraphQL types #129
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
Drops Encodable requirement on GraphQL types #129
Conversation
Changing to draft. It turns out that the |
Would this make connections of interfaces/unions possible? |
28f6bbe
to
86a1e69
Compare
I don't think so. I think that's more a limitation in how the GraphQL type system is implemented than a Swift codability restriction. |
My understanding is the only reason connections of interfaces/ unions doesn't work is that node needs to be encodable. I've created custom connections where the a swift protocol is the node. |
@NeedleInAJayStack have you tried |
86a1e69
to
ffcb6d6
Compare
@paulofaria OMG, you're a genius! I had no idea that existed and it totally fixed the problem. Thanks! |
@cshadek Oh okay! Yeah, if that's the case, then this probably will fix it! |
ffcb6d6
to
5278908
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super awesome! I'm just curious as to why a type would not be able to conform to Codable
. 😄
😆 It's a good question... My primary use case is that I have an object with a property that contains existentials, which makes it pretty hard to decode without a huge typeswitch. I don't really want to expose this property in GraphQL, but I do want to expose things derived from it. For example: struct A {
let b: [any B] // Not exposed in GraphQL, but important to keep around.
var bDescription: String { // Exposed in GraphQL
return b.map { $0.description }
}
} |
Gotcha, makes sense! Just out of curiosity, 😄. Are you using an existential because the array is not homogeneous so generics wouldn't work? |
Yeah, exactly. It's a heterogeneous array. |
This drops unnecessary Codable conformance from GraphQL-injected types. More specifically, output types are never encoded or decoded - only the resulting leaf Scalars are encoded. While this PR removes the restriction that all output types are codable, it still requires Encodability on Scalars and Decodability on Arguments. Decodable conformance is technically removed from Input objects, but typically still enforced through the decodable Argument requirement.
This change is useful if you have a complex, non-codable type that you would like to pass through resolver chains.