Write tests for a GraphQL query in my API
Writes tests for one GraphQL query or mutation in an API you own, from the pasted schema, with errors and permissions covered.
Task:
Write tests in [test framework and language] for the GraphQL operation named [operation name], using the schema in the material.
Context:
The API is mine and I test against [local or test environment, never production]. Requests need [authentication method]. The operation should [what it should do].
Rules:
- Read the schema first and list the types, arguments and nullable fields the operation touches.
- Write tests for a valid request, a missing required argument, a wrong type, an unauthorized caller and an empty result.
- Remember that GraphQL often returns status 200 with an errors field, and assert on that field where it applies.
- Select only the fields each test needs, and never assert on data that changes per run.
- Read endpoint URLs and tokens from environment variables and never ask me for secrets.
Result:
A list of the touched types in at most 5 lines, then the complete test file with comments, then 2 lines on how to run it.
Material:
[paste the relevant part of the GraphQL schema here]