{"record":{"id":"641dd205af609b7c","repo":"cayleygraph/cayley","slug":"multiple-fields-at-location-root-s","errorCode":null,"errorMessage":"multiple fields at location root %s","messagePattern":"multiple fields at location root (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/mql/build_iterator.go","lineNumber":84,"sourceCode":"\t\tif math.Floor(t) == t {\n\t\t\t// Treat it like an integer.\n\t\t\ts = shape.Lookup{quad.Int(t)}\n\t\t} else {\n\t\t\ts = shape.Lookup{quad.Float(t)}\n\t\t}\n\tcase string:\n\t\t// for JSON strings\n\t\ts = buildFixed(t)\n\tcase []interface{}:\n\t\t// for JSON arrays\n\t\tq.isRepeated[path] = true\n\t\tif len(t) == 0 {\n\t\t\ts = buildAllResult(path)\n\t\t\toptional = true\n\t\t} else if len(t) == 1 {\n\t\t\ts, optional, err = q.buildShape(t[0], path)\n\t\t} else {\n\t\t\terr = fmt.Errorf(\"multiple fields at location root %s\", path.DisplayString())\n\t\t}\n\tcase map[string]interface{}:\n\t\t// for JSON objects\n\t\ts, err = q.buildShapeMap(t, path)\n\tcase nil:\n\t\ts = buildAllResult(path)\n\t\toptional = true\n\tdefault:\n\t\terr = fmt.Errorf(\"Unknown JSON type: %T\", query)\n\t}\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\ts = shape.Save{\n\t\tFrom: s,\n\t\tTags: []string{string(path)},\n\t}\n\treturn s, optional, nil","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/query/mql/build_iterator.go#L66-L102","documentation":"In mql/build_iterator.go:84, buildShape handles a JSON array in the MQL query. An array at the root represents alternative field shapes; more than one element means multiple fields were specified at the same root location, which MQL does not support, so this error is thrown with the path's display string. A single-element array or empty array (match-all) are the only allowed forms.","triggerScenarios":"Executing a MQL query (mql.BuildIteratorTree) where a JSON array value contains two or more field definitions at the same location, e.g. [[{...},{...}]] style multiple alternatives.","commonSituations":"Hand-writing MQL queries that mix multiple top-level field sets, or programmatic query generation emitting an array with multiple query maps.","solutions":["Reduce the array at that location to a single field object.","Merge the multiple field definitions into one map if they should apply together.","Use separate queries if the alternatives are mutually exclusive.","Check the path string in the message to locate the offending query position."],"exampleFix":"// before\nquery := []interface{}{map[string]interface{}{\"name\": nil}, map[string]interface{}{\"age\": nil}}\n// after\nquery := map[string]interface{}{\"name\": nil, \"age\": nil}","handlingStrategy":"validation","validationCode":"func validateMQLArrayAtMostOne(v interface{}) error {\n  arr, ok := v.([]interface{})\n  if !ok || len(arr) <= 1 { return nil }\n  return fmt.Errorf(\"MQL arrays may contain at most one field spec, got %d\", len(arr))\n}","typeGuard":"func isSingleSpecArray(v interface{}) bool {\n  a, ok := v.([]interface{})\n  return ok && len(a) <= 1\n}","tryCatchPattern":"it, err := mql.BuildIteratorTree(query)\nif err != nil {\n  if strings.Contains(err.Error(), \"multiple fields at location root\") {\n    return fmt.Errorf(\"merge multiple field objects into one in query\")\n  }\n  return err\n}","preventionTips":["Merge field sets into a single map instead of multi-element arrays","Keep query generators emitting one spec per location","Validate MQL query JSON against the dialect before execution"],"tags":["mql","query","go","validation"],"backgroundTag":"invalid-query-parameter","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}