cube-js/cube · error
Variable "${argument.name.value}" is not defined
Error message
Variable "${argument.name.value}" is not defined What it means
During GraphQL-to-Cube query translation, getArgumentValue handles the `where` and `orderBy` arguments. If the argument is a GraphQL Variable and the corresponding entry in the variables map is undefined, this Error is thrown naming the missing variable. Unlike error 28, this path covers top-level field arguments rather than nested argument values.
Source
Thrown at packages/cubejs-api-gateway/src/graphql.ts:250
}), {});
case 'Variable':
if (variables?.[value.name.value] === undefined) {
throw new Error(`Variable "${value.name.value}" is not defined`);
}
return variables[value.name.value];
default:
return undefined;
}
}
function getArgumentValue(node: FieldNode, argName: string, variables: Record<string, any> = {}) {
const argument = node.arguments?.find(a => a.name.value === argName)?.value;
if (argument?.kind === 'Variable') {
const varValue = variables[argument.name.value];
if (varValue === undefined) {
throw new Error(`Variable "${argument.name.value}" is not defined`);
}
return variables[argument.name.value];
}
return argument ? parseArgumentValue(argument, variables) : argument;
}
function getMemberType(metaConfig: any, cubeName: string, memberName: string) {
const cubeConfig = metaConfig.find(cube => (cube.config.name === cubeName) || cube.config.name === capitalize(cubeName));
if (!cubeConfig) return undefined;
return [MemberType.MEASURES, MemberType.DIMENSIONS].find((memberType) => (cubeConfig.config[memberType]
.findIndex(entry => entry.name === `${cubeName}.${memberName}` || entry.name === `${capitalize(cubeName)}.${memberName}`) !== -1
));
}
function whereArgToQueryFilters(
whereArg: Record<string, any>,View on GitHub (pinned to 7d981676b3)
Solutions
- Always supply defined values for every variable used in where/orderBy arguments when calling the GraphQL API.
- Align variable names between the query document and the variables payload (fix typos).
- For optional filters, build the query dynamically to inline a literal filter or omit the where argument instead of passing an undefined variable.
- Use a GraphQL client that validates variables against declared variable definitions before sending.
Example fix
// before
request(query, {}); // query uses $whereFilter
// after
request(query, { whereFilter: { member: 'Orders.status', operator: 'equals', values: ['shipped'] } }); Defensive patterns
Strategy: validation
Validate before calling
function assertWhereOrderByVars(query, variables = {}) {
query.definitions.forEach(d => (d.selectionSet?.selections || []).forEach(sel =>
(sel.arguments || []).forEach(a => {
if (['where', 'orderBy'].includes(a.name.value) && a.value?.kind === 'Variable' && variables[a.value.name.value] === undefined) {
throw new Error(`Missing ${a.name.value} variable: ${a.value.name.value}`);
}
})));
} Type guard
function whereVarProvided(variables, name = 'whereFilter') {
return variables ? variables[name] !== undefined : false;
} Try / catch
try {
const result = await cubeApi.load(cubeQueryFromGraphql);
} catch (e) {
if (/is not defined/.test(e.message)) {
// retry with the missing where/orderBy variable filled from app state
}
throw e;
} Prevention
- Build where/orderBy variables in one typed factory function used by all clients
- Strip unused variable declarations from documents when their values are absent
- Use GraphQL clients (apollo/urql) that warn on missing variables before the request is sent
When it happens
Trigger: A GraphQL query like `{ cube { orders(where: $whereFilter) { measures } } }` executed with a variables object lacking `whereFilter` (or holding undefined for it), via the Cube GraphQL API's variable-driven where/orderBy.
Common situations: Client-side GraphQL clients sending variables objects that omit keys for optional filters; renames of variables in the document without updating the variables map; server-side resolvers building variables conditionally and skipping empty filters.
Related errors
- Variable "${value.name.value}" is not defined
- Can't parse date: '${from}'
- Can't parse date: '${to}'
- Can't parse date: '${dateString}'
- Invalid Job query format: ${error.message || error.toString(
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/7ddc53368a00c485.
Report an issue: GitHub.