0

I've just started developing a graphQL API using graphql-dotnet. I've searched through the documentation but I couldn't find anything on what to do if a record is not found for given arguments. The reference implementations I checked (github, starwars graphql implementations etc) return null, and some of them include an errors field with some additional detail.

What I'm wondering is, are there any established best practices for this and how to handle it in an elegant way with graphql-dotnet.

Thank you.

Rudithus
  • 183
  • 13

1 Answers1

0

If the data type of that field is a list , returning a NULL if no records are found seems awkward to me and I would return an empty list.

On the other hand , if the data type of that field is a single value , it must return NULL. To have better developer experience ,it is always good to provide more information through the error fields to let developers know why no result is returned which can be due to the inputting ID is not correct or user does not have enough permission to view that record or etc. Developer can then display the message from the error field to the UI to improve the user experience of the application.

Ken Chan
  • 84,777
  • 26
  • 143
  • 172