prismake / typegql

Create GraphQL schema with TypeScript classes.
https://prismake.github.io/typegql/
MIT License
423 stars 21 forks source link

Question: Why is the Arg decorator not nullable by default? #67

Closed capaj closed 5 years ago

capaj commented 5 years ago

Is there a reason other than personal preference why Arg decorator is not nullable by default same as Field?

pie6k commented 5 years ago

I'd say having arguments not-nullable by default is safer.

By default, your code doesn't have to handle custom cases when some argument is null.

If args would be nullable by default, you might have some resolver expecting an argument to be present and skip checking it. It could potentially break your code.

Current default may 'break' your request (so you'll have either to modify your frontend or to enable nullable argument), but it'll not break resolver code which I believe is a good approach.

If you want to make some argument optional (and you 'agree' to provide a code to handle such case) you have to explicitly opt-in (and show to other devs reading your code "I know what I'm doing").

I think it's not just my personal preference but some kind of logical conclusion.

capaj commented 5 years ago

Makes sense.