Hi anonymous user , thank you for your question. To check if a user exists or not, I would first recommend using the Graph Explorer. This way you can test your queries to make sure they work.
For your question, I recommend using this reference to get a user. And if the response is null, you simply have no user. Just like you have in your example. I would sign in to the graph explorer and test your query. This way you can use your own directory instead of the sample data provided.
Please let me know if you have any questions and I can help you further!
If this answer helped you please mark it as "Verified" so other users can reference it.
Thank you,
James