Open Evertt opened 4 years ago
I like this key encoding strategy idea! It's probably a good option to give users of our API the option to change how the names of their fields and types work.
This is great!
In the case of Movie
the CodingKeys
have nothing to do with GraphZahl
. Since tmdb is just a wrapper of a REST API those are the keys for decoding the values from the REST API. So those keys are just to decode from the response of the REST API and I really wanted to rename some things.
GraphZahl doesn't rely on Codable or CodingKeys at all. This was a decision I made to keep it as extensible as possible. So that a wrapper like tmdb could read the values from an API and still return them in whatever format was better for GraphQL.
We probably need this for:
GraphZahl doesn't rely on Codable or CodingKeys at all.
Oh really? Funny, I just assumed it was all based on that.
Still happy that my idea appeals to you. ^_^
So I was just looking at your movie database demo repo and I saw this line. And I thought, a lot of lines could've been saved there if you could just use Foundation's JSONEncoder.KeyEncodingStrategy to configure the root
GraphQLSchema
object with.Okay I guess it feels a bit awkward to literally use the one from JSONEncoder, because that creates this awkward link between GraphZahl and JSONEncoder, but it would be easy enough to make your own.
So in this case the function
greetMe
would be represented to the outside world asgreet_me
. And then this strategy would obviously apply to every underlyingGraphQLObject
as well. So then you wouldn't need to write this code anymore:Because the
CodingKeys
would be auto-synthesized by the compiler anyway and the output representation would be decided by thestatic let codingKeyStrategy
defined on the rootGraphQLSchema
.