cayleygraph/cayley · error
label directive should have 0 or 1 argument
Error message
label directive should have 0 or 1 argument
What it means
The @label directive controls which labels (subgraphs) are traversed, and it accepts at most one argument. Supplying two or more arguments to @label is rejected with this error.
Source
Thrown at query/graphql/graphql.go:516
out.Labels = labels
name := fld.Name.Value
if fld.Alias != nil && fld.Alias.Value != "" {
out.Alias = fld.Alias.Value
} else {
out.Alias = name
}
out.Via, out.Rev = stringToVia(name)
// first check for "label" directive - it will affect all traversals
for _, d := range fld.Directives {
if d.Name == nil {
continue
}
switch d.Name.Value {
case "label":
if len(d.Arguments) == 0 {
out.Labels = nil
} else if len(d.Arguments) > 1 {
return out, fmt.Errorf("label directive should have 0 or 1 argument")
} else if a := d.Arguments[0]; a.Name == nil || a.Name.Value != "v" {
return out, fmt.Errorf("label directive should have 'v' argument")
} else {
vals, err := convValue(a.Value)
if err != nil {
return out, fmt.Errorf("error parsing label: %v", err)
}
out.Labels = vals
}
}
}
for _, d := range fld.Directives {
if d.Name == nil {
continue
}
switch d.Name.Value {
case "rev", "reverse":
if len(d.Arguments) == 0 {View on GitHub (pinned to 81dcd7d73e)
Solutions
- Use at most one argument: `@label(v: ...)`
- Pass multiple values via a list value in the single `v` argument if supported
- Remove extra arguments from the directive
Example fix
// before
q := "query { node @label(v: "a", rev: true) { id } }"
// after
q := "query { node @label(v: "a") { id } }" Defensive patterns
Strategy: validation
Validate before calling
function validateLabelDirective(field) {
const d = (field.directives || []).find(d => d.name.value === 'label');
if (d && d.arguments.length > 1) throw new Error('@label accepts at most one argument');
} Type guard
const hasValidLabelArgCount = (d) => !d || d.arguments.length <= 1;
Prevention
- Remember @label signature: @label or @label(v: ...)
- Lint directive usage against documented signatures
- Copy directive syntax from official examples only
When it happens
Trigger: A field directive `@label(v: "a", other: "b")` or any @label with len(d.Arguments) > 1 during convField, reached via Parse.
Common situations: Copy-pasted queries mixing dialects; guessing directive syntax; tools generating extra arguments on directives.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- unexpected arguments: %v (%d)
- label directive should have 'v' argument
- error parsing label: %v
- expected one predicate or path for recursive follow
- unexpected value type for %v: %T
AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06).
Data as JSON: /api/errors/3b106b1ff7998096.
Report an issue: GitHub.