dgraph-io/dgraph · error

Invalid function name: %s

Error message

Invalid function name: %s

What it means

filterCopy translates a DQL filter tree into a SubGraph. When a filter uses a function, the function name is checked against isValidFuncName; an unrecognized name yields "Invalid function name: %s". This is DQL query validation failing at graph-construction time (newGraph/treeCopy/filterCopy recursion).

Source

Thrown at query/query.go:465

	for _, mc := range src.Child {
		child := &mathTree{}
		if err := mathCopy(child, mc); err != nil {
			return err
		}
		dst.Child = append(dst.Child, child)
	}
	return nil
}

func filterCopy(sg *SubGraph, ft *dql.FilterTree) error {
	// Either we'll have an operation specified, or the function specified.
	if len(ft.Op) > 0 {
		sg.FilterOp = ft.Op
	} else {
		sg.Attr = ft.Func.Attr
		if !isValidFuncName(ft.Func.Name) {
			return errors.Errorf("Invalid function name: %s", ft.Func.Name)
		}

		if isUidFnWithoutVar(ft.Func) {
			sg.SrcFunc = &Function{Name: ft.Func.Name}
			if err := sg.populate(ft.Func.UID); err != nil {
				return err
			}
		} else {
			if ft.Func.Attr == "uid" {
				return errors.Errorf(`Argument cannot be "uid"`)
			}
			sg.createSrcFunction(ft.Func)
			sg.Params.NeedsVar = append(sg.Params.NeedsVar, ft.Func.NeedsVar...)
		}
	}
	for _, ftc := range ft.Child {
		child := &SubGraph{}
		if err := filterCopy(child, ftc); err != nil {

View on GitHub (pinned to 759e242be6)

Solutions

  1. Correct the function name to a valid DQL filter function (eq, lt, le, gt, ge, has, uid, allofterms, anyofterms, allofterms, match, type, etc.)
  2. Check whether the function is root-only (e.g. some funcs allowed at func: but not in @filter)
  3. Upgrade Dgraph if the function exists only in a newer version

Example fix

// before
{ q(func: type(Person)) @filter(equals(name, "Alice")) { uid } }
// after
{ q(func: type(Person)) @filter(eq(name, "Alice")) { uid } }
Defensive patterns

Strategy: validation

Validate before calling

// Go client-side: validate filter functions before sending query
var validFilterFuncs = map[string]bool{"eq":true,"lt":true,"le":true,"gt":true,"ge":true,"has":true,"uid":true,"allofterms":true,"anyofterms":true,"alloftext":true,"anyoftext":true,"match":true,"type":true}
for name := range parsedFilterFuncs {
    if !validFilterFuncs[name] {
        return fmt.Errorf("invalid filter function: %s", name)
    }
}

Type guard

func isValidFilterFunc(name string) bool {
    valid := []string{"eq","lt","le","gt","ge","has","uid","allofterms","anyofterms","alloftext","anyoftext","match","type"}
    return slices.Contains(valid, name)
}

Try / catch

_, err := txn.Query(ctx, dql)
var te *api.TxnFinishedError // generic path
if err != nil && strings.Contains(err.Error(), "Invalid function name") {
    fn := extractFuncName(err.Error())
    return fmt.Errorf("check DQL docs for function %q; did you mean eq/allofterms?", fn)
}

Prevention

When it happens

Trigger: A filter with a misspelled or non-existent function, e.g. `@filter(alike(name, "x"))` or `@filter(equals(name, "x"))` instead of valid names like eq/le/ge/lt/gt/allofterms/anyofterms/uid/has.

Common situations: Typos in filter functions (eq vs equals), functions valid only in root (not allowed in filter) contexts, or copied SQL-style function names.

Related errors


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