{"record":{"id":"f1d4a5e8f1d64637","repo":"dgraph-io/dgraph","slug":"while-converting-to-subgraph","errorCode":null,"errorMessage":"while converting to subgraph","messagePattern":"while converting to subgraph","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/query.go","lineNumber":2882,"sourceCode":"\tstop := x.SpanTimer(span, \"query.ProcessQuery\")\n\tdefer stop()\n\n\t// Vars stores the processed variables.\n\treq.Vars = make(map[string]varValue)\n\tloopStart := time.Now()\n\tqueries := req.DqlQuery.Query\n\t// first loop converts queries to SubGraph representation and populates ReadTs And Cache.\n\tfor i := range queries {\n\t\tgq := queries[i]\n\n\t\tif gq == nil || (len(gq.UID) == 0 && gq.Func == nil && len(gq.NeedsVar) == 0 &&\n\t\t\tgq.Alias != \"shortest\" && !gq.IsEmpty) {\n\t\t\treturn errors.Errorf(\"Invalid query. No function used at root and no aggregation\" +\n\t\t\t\t\" or math variables found in the body.\")\n\t\t}\n\t\tsg, err := ToSubGraph(ctx, gq)\n\t\tif err != nil {\n\t\t\treturn errors.Wrapf(err, \"while converting to subgraph\")\n\t\t}\n\t\tsg.recurse(func(sg *SubGraph) {\n\t\t\tsg.ReadTs = req.ReadTs\n\t\t\tsg.Cache = req.Cache\n\t\t})\n\t\tspan.AddEvent(\"Query parsed\")\n\t\treq.Subgraphs = append(req.Subgraphs, sg)\n\t}\n\treq.Latency.Parsing += time.Since(loopStart)\n\n\texecStart := time.Now()\n\thasExecuted := make([]bool, len(req.Subgraphs))\n\tnumQueriesDone := 0\n\n\t// canExecute returns true if a query block is ready to execute with all the variables\n\t// that it depends on are already populated or are defined in the same block.\n\tcanExecute := func(idx int) bool {\n\t\tqueryVars := req.DqlQuery.QueryVars[idx]","sourceCodeStart":2864,"sourceCodeEnd":2900,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/query.go#L2864-L2900","documentation":"This error wraps any failure that occurs while converting a parsed GraphQL+- query block into an internal SubGraph execution structure (query.ToSubGraph). It fires during query processing when the root query is valid enough to attempt conversion but ToSubGraph encounters an unsupported or inconsistent query shape. The wrap adds context to the underlying conversion error.","triggerScenarios":"Calling Dgraph query HTTP /query or gRPC Query with a root query that ToSubGraph rejects: unsupported root functions, malformed aggregation/math variable usage, invalid query syntax that still parses, or invalid combinations of query features at root.","commonSituations":"Typing a query with an unsupported root construct (e.g. a root function mixed incorrectly with aggregates), version differences where a syntax is no longer supported at root, or programmatically generated DQL with malformed body variables.","solutions":["Inspect the wrapped inner error in the message chain for the actual conversion failure cause","Simplify the query: run only the root predicates first, then add features back one at a time","Verify query syntax against DQL docs for your Dgraph version (root function/aggregation rules changed across versions)","If using root functions like eq/anyofterms, confirm the predicate is indexed"],"exampleFix":"// before (invalid mix at root)\n{\n  me(func: uid(0x1)) @filter(eq(name, \"x\")) {\n    ~parent { uid }\n  }\n}\n// after: use func at root or move filter to body\n{\n  me(func: eq(name, \"x\")) {\n    ~parent { uid }\n  }\n}","handlingStrategy":"try-catch","validationCode":"// Validate query syntax before sending\ndql := `{ me(func: eq(name, \"x\")) { name } }`\nif !strings.Contains(dql, \"func:\") && !strings.Contains(dql, \"as var\") {\n    return errors.New(\"root must have a function or aggregation\")\n}","typeGuard":null,"tryCatchPattern":"resp, err := dg.NewTxn().Query(ctx, dql)\nif err != nil {\n    if strings.Contains(err.Error(), \"while converting to subgraph\") {\n        // log full wrapped chain, simplify query and retry\n    }\n    return err\n}","preventionTips":["Test queries in Ratel before shipping them in code","Keep DQL syntax pinned to your Dgraph server version's docs","Index all predicates used in root functions"],"tags":["dql","query-parsing","dgraph"],"backgroundTag":"query-conversion-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}