Skip to content
Latchkey

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.

Apollo Server
{
  "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

  1. List the non-null variables in the operation signature.
  2. Confirm each one is a key in the request variables object with a non-null value.
  3. Fix any name mismatch between the declaration and the payload.
JSON
// 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.

GraphQL
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.

Frequently asked questions

What causes ""of required type ... was not provided""?
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.
How do I fix "of required type ... was not provided"?
Send every required variable

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card