dgraph-io/dgraph · error

Cannot specify order at both args and facets

Error message

Cannot specify order at both args and facets

What it means

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.

Solutions

  1. Keep only one ordering: remove the args-level orderasc/orderdesc/orderby if facet order is what you need
  2. Or remove the @facets(orderby:...) clause if node ordering is primary; facets can still be fetched with plain @facets(facet-name)
  3. If both orders are truly needed, split across two aliased query branches

Example fix

// before
{
  me(func: uid(0x1)) {
    friend(orderasc: name) @facets(orderby: weight)
  }
}
// after
{
  me(func: uid(0x1)) {
    friend @facets(orderby: weight) {
      name
    }
  }
}
Defensive patterns

Strategy: validation

Validate before calling

function assertSingleOrderSource(node) {
  const hasArgOrder = ['orderasc','orderdesc','orderby'].some(a => a in node.args);
  const hasFacetOrder = /@facets\s*\([^)]*order/.test(node.fieldSrc || '');
  if (hasArgOrder && hasFacetOrder) throw new Error('Specify order either in args or in facets, not both');
}

Type guard

const hasConflictingOrders = (n) => n.args && (n.args.orderasc || n.args.orderdesc || n.args.orderby) && n.facetsOrder && n.facetsOrder.length > 0;

Try / catch

try {
  await txn.query(q);
} catch (e) {
  if (e.message.includes('order at both args and facets')) {
    throw new Error('Drop either the args-level order or @facets(orderby:...)');
  }
  throw e;
}

Prevention

When it happens

Trigger: 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)`.

Common situations: 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.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/051bad72293c4f73. Report an issue: GitHub.

Appendix: source

Thrown at query/query.go:604

		if gchild.IsCount {
			if len(gchild.Children) != 0 {
				return errors.New("Node with count cannot have child attributes")
			}
			args.DoCount = true
		}

		for argk := range gchild.Args {
			if !isValidArg(argk) {
				return errors.Errorf("Invalid argument: %s", argk)
			}
		}
		if err := args.fill(gchild); err != nil {
			return err
		}

		if len(args.Order) != 0 && len(args.FacetsOrder) != 0 {
			return errors.Errorf("Cannot specify order at both args and facets")
		}

		dst := &SubGraph{
			Attr:   gchild.Attr,
			Params: args,
		}
		if gchild.MathExp != nil {
			mathExp := &mathTree{}
			if err := mathCopy(mathExp, gchild.MathExp); err != nil {
				return err
			}
			dst.MathExp = mathExp
		}

		if gchild.Func != nil &&
			(gchild.Func.IsAggregator() || gchild.Func.IsPasswordVerifier()) {
			if len(gchild.Children) != 0 {
				return errors.Errorf("Node with %q cant have child attr", gchild.Func.Name)

View on GitHub (pinned to 759e242be6)