-
I'm sure there must be a reason (valid or historical) but distinguishing between input and output types seems to serve no real purpose and comes with a significant cost. By no means the authority but perhaps a good starting point are the reasons that ChatGPT give:
Please ChatGPT, do tell...
Unless your server side language also has this distinction then there is no safety. Once deserialised then all safety from this is gone. This is especially for a structurally typed language. It is not GraphQL's job to prevent someone from mutating data when querying. This is a fairly tough problem to solve and it requires some sort of effect system with capability checking (i.e. you can only mutate if you prove you are in a mutable context).
Being able to define validation rules and constraints is the bread and butter of any type system. It is not unique to "input" types. If something is relevant to input data but not output data then it is a different type not a different kind of type.
Serialisation and deserialisation is not a property of a type. If you use it as input then you must provide a deserialiser. If you use it as output then you must provide a serialiser. Nothing changes here.
True but this is not where the intent should come from. If you use it in parentheses
If your input type no longer matches your output type then it is just a new type.
But the same thing applies to output types. The only difference comes from the intent which we get from the usage. If it is input data then the client must provide the required fields. If it is output data then the server must provide the require fields. There should be no distinction between input and output types. It doubles the complexity of tooling. It limits what we can do and creates unnecessary irregularities (looking at you #488 and #825). If you use a type as input then call it an input type if you wish, heck even suffix it with Imagine if your programming language forced you to biforcate all your types into those which could be passed into a function and those that could be returned. It would be rediculuous in a nominally typed language and pointless in a structurally typed language yet this is what we find with GraphQL. If you are unconvinced by any argument made here then that is your right and you should be free to use an Now I duck and hide under my desk whilst the bombarding begins and I curse ChatGPT for leading me astray once again. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I’m not going to spend my time refuting each of ChatGPT’s answers, a tool which generates text that is answer-shaped but very often wrong. (It doesn’t even seem to acknowledge that inputs can be used in queries and subscriptions, input objects are not solely focussed on mutations!) I’ll admit I didn’t read much past its first answer, so if I have missed something important please let me know. Instead, please read this which answers your original question more directly: #932 (comment) |
Beta Was this translation helpful? Give feedback.
I’m not going to spend my time refuting each of ChatGPT’s answers, a tool which generates text that is answer-shaped but very often wrong. (It doesn’t even seem to acknowledge that inputs can be used in queries and subscriptions, input objects are not solely focussed on mutations!) I’ll admit I didn’t read much past its first answer, so if I have missed something important please let me know.
Instead, please read this which answers your original question more directly: #932 (comment)