rivantsov / ngraphql

GraphQL .NET Server and Client
MIT License
43 stars 5 forks source link

[Question] Null annotation #8

Closed jasonlaw closed 3 years ago

jasonlaw commented 3 years ago

Hi @rivantsov ,

May I know is the Null annotation only useful for input type? For output fields, I don't see any different with or without it, I could be wrong.

Thanks!

rivantsov commented 3 years ago

Of course it is important for output types. [Null] signals that field value (like string) can be null, its type appears in SchemaDoc as 'String', without bang. Without [Null] it would be 'String!', means value guaranteed to be not null. And if your resolver returns null, the engine will (should) catch it and signal server error, failure to follow contract.

jasonlaw commented 3 years ago

Not sure if that is bug or not, I suppose the email cannot be null in this case right?

image

image

image

rivantsov commented 3 years ago

yep, looks like a bug, the engine supposed to catch it and return error. Is there errors node in response? On the other hand, it should be more like your code's responsibility to never return null, the engine is an extra enforcing check over your code. It might be argued that often it's better return some data to the client than simply a server error. But error should be returned anyway in addition to some data.

jasonlaw commented 3 years ago

There's no error nodes in the response. That's why I was confused with the annotation.

rivantsov commented 3 years ago

ok, lets register it as a bug, will fix it

rivantsov commented 3 years ago

should be fixed now

jasonlaw commented 3 years ago

tested ok. thanks!