cayleygraph/cayley · error

error parsing label: %v

Error message

error parsing label: %v

What it means

The value supplied to @label's `v` argument could not be converted by convValue into quad values (labels must be resolvable to IRIs/strings). The underlying conversion error is wrapped with this prefix.

Source

Thrown at query/graphql/graphql.go:522

	}
	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 {
				out.Rev = out.Rev != true
			} else {
				out.Has, err = argsToHas(out.Has, d.Arguments, true, out.Labels)
				if err != nil {
					return
				}

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Pass a plain string or valid IRI value: `@label(v: "myLabel")`
  2. If using a variable ($v), ensure it is supplied in the query variables and converts to a string
  3. Inspect the wrapped inner error (%v) for the exact conversion failure

Example fix

// before
q := "query { node @label(v: $missing) { id } }" // variable not provided
// after
q := "query { node @label(v: "myLabel") { id } }"
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure label values are plain strings or valid IRIs before sending
function isConvertibleLabel(v) {
  return typeof v.value === 'string' || (v.kind === 'Variable' && typeof variables[v.name.value] === 'string');
}

Type guard

const isStringOrIRI = (x) => typeof x === 'string' || /^https?:\/\//.test(x ?? '');

Try / catch

result, err := engine.Parse(ctx, q)
if err != nil {
  if strings.HasPrefix(err.Error(), "error parsing label:") {
    return fmt.Errorf("check @label(v: ...) value is a string/IRI and variables are provided: %w", err)
  }
  return err
}

Prevention

When it happens

Trigger: A @label directive whose argument value is an unsupported literal kind (e.g. an object value, a variable that fails conversion, or another non-convertible node), causing convValue to return an error inside convField.

Common situations: Passing GraphQL variables not provided in the variables map; using object/list literals where a string/IRI is expected; schema tooling emitting enum or object values for the label.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of cayleygraph/cayley@81dcd7d73e (2026-09-06). Data as JSON: /api/errors/fd012f64a147f21a. Report an issue: GitHub.