{"record":{"id":"051bad72293c4f73","repo":"dgraph-io/dgraph","slug":"cannot-specify-order-at-both-args-and-facets","errorCode":null,"errorMessage":"Cannot specify order at both args and facets","messagePattern":"Cannot specify order at both args and facets","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/query.go","lineNumber":604,"sourceCode":"\n\t\tif gchild.IsCount {\n\t\t\tif len(gchild.Children) != 0 {\n\t\t\t\treturn errors.New(\"Node with count cannot have child attributes\")\n\t\t\t}\n\t\t\targs.DoCount = true\n\t\t}\n\n\t\tfor argk := range gchild.Args {\n\t\t\tif !isValidArg(argk) {\n\t\t\t\treturn errors.Errorf(\"Invalid argument: %s\", argk)\n\t\t\t}\n\t\t}\n\t\tif err := args.fill(gchild); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif len(args.Order) != 0 && len(args.FacetsOrder) != 0 {\n\t\t\treturn errors.Errorf(\"Cannot specify order at both args and facets\")\n\t\t}\n\n\t\tdst := &SubGraph{\n\t\t\tAttr:   gchild.Attr,\n\t\t\tParams: args,\n\t\t}\n\t\tif gchild.MathExp != nil {\n\t\t\tmathExp := &mathTree{}\n\t\t\tif err := mathCopy(mathExp, gchild.MathExp); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tdst.MathExp = mathExp\n\t\t}\n\n\t\tif gchild.Func != nil &&\n\t\t\t(gchild.Func.IsAggregator() || gchild.Func.IsPasswordVerifier()) {\n\t\t\tif len(gchild.Children) != 0 {\n\t\t\t\treturn errors.Errorf(\"Node with %q cant have child attr\", gchild.Func.Name)","sourceCodeStart":586,"sourceCodeEnd":622,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/query.go#L586-L622","documentation":"Ordering can be supplied either as orderasc/orderdesc/orderby arguments or inside a @facets(...) order clause, but not both at once, since the two orderings would conflict. treeCopy compares args.Order and args.FacetsOrder after filling arguments and rejects the combination.","triggerScenarios":"A node has both `orderasc: predicate` (or orderby) in args and `@facets(orderby: ...)` on the same child, e.g. `friend(orderasc: name) @facets(orderby: weight)`.","commonSituations":"Users wanting to order nodes and simultaneously order facets copy both forms into one line; older queries with facet ordering later augmented with node-level ordering without removing one.","solutions":["Keep only one ordering: remove the args-level orderasc/orderdesc/orderby if facet order is what you need","Or remove the @facets(orderby:...) clause if node ordering is primary; facets can still be fetched with plain @facets(facet-name)","If both orders are truly needed, split across two aliased query branches"],"exampleFix":"// before\n{\n  me(func: uid(0x1)) {\n    friend(orderasc: name) @facets(orderby: weight)\n  }\n}\n// after\n{\n  me(func: uid(0x1)) {\n    friend @facets(orderby: weight) {\n      name\n    }\n  }\n}","handlingStrategy":"validation","validationCode":"function assertSingleOrderSource(node) {\n  const hasArgOrder = ['orderasc','orderdesc','orderby'].some(a => a in node.args);\n  const hasFacetOrder = /@facets\\s*\\([^)]*order/.test(node.fieldSrc || '');\n  if (hasArgOrder && hasFacetOrder) throw new Error('Specify order either in args or in facets, not both');\n}","typeGuard":"const hasConflictingOrders = (n) => n.args && (n.args.orderasc || n.args.orderdesc || n.args.orderby) && n.facetsOrder && n.facetsOrder.length > 0;","tryCatchPattern":"try {\n  await txn.query(q);\n} catch (e) {\n  if (e.message.includes('order at both args and facets')) {\n    throw new Error('Drop either the args-level order or @facets(orderby:...)');\n  }\n  throw e;\n}","preventionTips":["Decide one ordering source per node: node order or facet order","Builders should strip args-order when facet order is set (or vice versa)","Code-review facet queries for combined order directives"],"tags":["dgraph","query","ordering","facets"],"backgroundTag":"conflicting-query-options","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}