{"record":{"id":"7ddc53368a00c485","repo":"cube-js/cube","slug":"variable-argument-name-value-is-not-defined","errorCode":null,"errorMessage":"Variable \"${argument.name.value}\" is not defined","messagePattern":"Variable \"(.+?)\" is not defined","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-api-gateway/src/graphql.ts","lineNumber":250,"sourceCode":"      }), {});\n    case 'Variable':\n      if (variables?.[value.name.value] === undefined) {\n        throw new Error(`Variable \"${value.name.value}\" is not defined`);\n      }\n\n      return variables[value.name.value];\n    default:\n      return undefined;\n  }\n}\n\nfunction getArgumentValue(node: FieldNode, argName: string, variables: Record<string, any> = {}) {\n  const argument = node.arguments?.find(a => a.name.value === argName)?.value;\n\n  if (argument?.kind === 'Variable') {\n    const varValue = variables[argument.name.value];\n    if (varValue === undefined) {\n      throw new Error(`Variable \"${argument.name.value}\" is not defined`);\n    }\n    return variables[argument.name.value];\n  }\n\n  return argument ? parseArgumentValue(argument, variables) : argument;\n}\n\nfunction getMemberType(metaConfig: any, cubeName: string, memberName: string) {\n  const cubeConfig = metaConfig.find(cube => (cube.config.name === cubeName) || cube.config.name === capitalize(cubeName));\n  if (!cubeConfig) return undefined;\n\n  return [MemberType.MEASURES, MemberType.DIMENSIONS].find((memberType) => (cubeConfig.config[memberType]\n    .findIndex(entry => entry.name === `${cubeName}.${memberName}` || entry.name === `${capitalize(cubeName)}.${memberName}`) !== -1\n  ));\n}\n\nfunction whereArgToQueryFilters(\n  whereArg: Record<string, any>,","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-api-gateway/src/graphql.ts#L232-L268","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nrequest(query, {}); // query uses $whereFilter\n// after\nrequest(query, { whereFilter: { member: 'Orders.status', operator: 'equals', values: ['shipped'] } });","handlingStrategy":"validation","validationCode":"function assertWhereOrderByVars(query, variables = {}) {\n  query.definitions.forEach(d => (d.selectionSet?.selections || []).forEach(sel =>\n    (sel.arguments || []).forEach(a => {\n      if (['where', 'orderBy'].includes(a.name.value) && a.value?.kind === 'Variable' && variables[a.value.name.value] === undefined) {\n        throw new Error(`Missing ${a.name.value} variable: ${a.value.name.value}`);\n      }\n    })));\n}","typeGuard":"function whereVarProvided(variables, name = 'whereFilter') {\n  return variables ? variables[name] !== undefined : false;\n}","tryCatchPattern":"try {\n  const result = await cubeApi.load(cubeQueryFromGraphql);\n} catch (e) {\n  if (/is not defined/.test(e.message)) {\n    // retry with the missing where/orderBy variable filled from app state\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["graphql","variables","where-filter","validation"],"backgroundTag":"graphql-variable-not-defined","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}