5. You want to ensure your GraphQL schema enforces that every Post has a non-empty title and an optional content. Which testing approach best validates this behavior?
hard
A. Write tests that accept any title value and ignore content field.
B. Write tests that only query Post fields without mutations.
C. Write tests that check if content is always returned as an empty string.
D. Write tests that send mutations with empty title and expect errors, and mutations with missing content to succeed.
Solution
Step 1: Identify validation goals
We want to ensure title is non-empty (required) and content is optional.
Step 2: Choose tests that check required and optional fields
Tests should try sending empty title to confirm errors, and omit content to confirm success.
Final Answer:
Write tests that send mutations with empty title and expect errors, and mutations with missing content to succeed. -> Option D
Quick Check:
Test required fields with errors, optional fields with success [OK]
Hint: Test required fields cause errors when empty, optional fields can be missing [OK]