GraphQL "Variable X of required type Y! was not provided" in CI
A GraphQL operation declared a variable with a non-null (!) type, but the request body omitted it from the variables object. Validation fails before execution with a BAD_USER_INPUT error.
What this error means
An integration test fails with "Variable \"$id\" of required type \"ID!\" was not provided." The variables map was empty, missing the key, or sent it as null.
{
"errors": [{
"message": "Variable \"$id\" of required type \"ID!\" was not provided.",
"extensions": { "code": "BAD_USER_INPUT" }
}]
}Common causes
The variables object omits the key
The request sends the query but a variables map that lacks the required key, or sends an empty object, so a non-null variable resolves to undefined.
A name mismatch between operation and payload
The variable is declared $id but the payload sends userId, so the declared variable is never supplied.
How to fix it
Send every required variable
- List the non-null variables in the operation signature.
- Confirm each one is a key in the request
variablesobject with a non-null value. - Fix any name mismatch between the declaration and the payload.
// request body sent by the test client
{
"query": "query($id: ID!) { user(id: $id) { name } }",
"variables": { "id": "42" }
}Make the variable optional only if the schema allows it
If absence is valid, drop the ! and give the argument a default; do not silently pass null where the schema forbids it.
query($id: ID = "1") { user(id: $id) { name } }How to prevent it
- Build request payloads from typed bindings so required variables are enforced at compile time.
- Assert on response.errors in integration tests, not just HTTP status.
- Keep variable names identical between the operation and the client call.