{"record":{"id":"337fcf060625df5a","repo":"dgraph-io/dgraph","slug":"from-to-can-t-be-nil-for-shortest-path","errorCode":null,"errorMessage":"from/to can't be nil for shortest path","messagePattern":"from/to can't be nil for shortest path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/query.go","lineNumber":738,"sourceCode":"\t\t\t\treturn err\n\t\t\t}\n\t\t\targs.MinWeight = minWeight\n\t\t} else if !ok {\n\t\t\targs.MinWeight = -math.MaxFloat64\n\t\t}\n\n\t\tif v, ok := gq.Args[\"maxfrontiersize\"]; ok {\n\t\t\tmaxfrontiersize, err := strconv.ParseInt(v, 0, 64)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\targs.MaxFrontierSize = maxfrontiersize\n\t\t} else if !ok {\n\t\t\targs.MaxFrontierSize = math.MaxInt64\n\t\t}\n\n\t\tif gq.ShortestPathArgs.From == nil || gq.ShortestPathArgs.To == nil {\n\t\t\treturn errors.Errorf(\"from/to can't be nil for shortest path\")\n\t\t}\n\t\tif len(gq.ShortestPathArgs.From.UID) > 0 {\n\t\t\targs.From = gq.ShortestPathArgs.From.UID[0]\n\t\t}\n\t\tif len(gq.ShortestPathArgs.To.UID) > 0 {\n\t\t\targs.To = gq.ShortestPathArgs.To.UID[0]\n\t\t}\n\t}\n\n\tif v, ok := gq.Args[\"first\"]; ok {\n\t\tfirst, err := strconv.ParseInt(v, 0, 32)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\targs.Count = int(first)\n\t}\n\treturn nil\n}","sourceCodeStart":720,"sourceCodeEnd":756,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/query.go#L720-L756","documentation":"A shortest-path query requires both from and to arguments, each resolving to UID values. fill() inspects gq.ShortestPathArgs and errors if From or To is nil — meaning the query omitted one of them or the provided value did not resolve to a UID node.","triggerScenarios":"Sending `shortest(from: 0x1)` without to; `shortest(to: 0x2)` without from; passing a name-string that Dgraph could not resolve to a UID so the arg remains nil; malformed JSON/RPC payload where shortest_path_args lacks from or to.","commonSituations":"Hand-built queries missing one endpoint; variable interpolation producing empty from/to; clients using names instead of UIDs with 0x notation in GraphQL+-; API consumers porting from engines with single-source path queries.","solutions":["Supply both endpoints with valid hex UIDs: `shortest(from: 0x1, to: 0x2)`","Resolve names to UIDs first (query for the uid by name) and use the resolved values","Check that query variables actually substitute non-empty from/to values before sending"],"exampleFix":"// before\nquery {\n  path as shortest(from: 0x1) { friend }\n}\n// after\nquery {\n  path as shortest(from: 0x1, to: 0x2) { friend }\n}","handlingStrategy":"validation","validationCode":"function assertShortestEndpoints(q) {\n  if (!q.from || !q.to) throw new Error('shortest requires both from and to UIDs');\n  if (!/^0x[0-9a-fA-F]+$/.test(q.from) || !/^0x[0-9a-fA-F]+$/.test(q.to)) {\n    throw new Error('from/to must be resolved UIDs in 0x form');\n  }\n}","typeGuard":"const hasShortestArgs = (q) => Boolean(q.shortestPathArgs && q.shortestPathArgs.from != null && q.shortestPathArgs.to != null && (q.shortestPathArgs.from.uid?.length ?? 0) > 0 && (q.shortestPathArgs.to.uid?.length ?? 0) > 0);","tryCatchPattern":"try {\n  await txn.query(q);\n} catch (e) {\n  if (e.message.includes(\"from/to can't be nil\")) {\n    throw new Error('Resolve both endpoints to UIDs before issuing shortest');\n  }\n  throw e;\n}","preventionTips":["Always resolve names to UIDs (0x...) before building shortest queries","Verify variable substitution leaves from/to non-empty","Build shortest queries through a helper that requires both endpoints as parameters"],"tags":["dgraph","query","shortest-path","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}