cayleygraph/cayley · error

unknown type of graph.Ref; not meant for this quadstore. app

Error message

unknown type of graph.Ref; not meant for this quadstore. apparently a %#v

What it means

ValuesOf converts graph.Ref values into this quadstore's internal primitive IDs; it only understands refs it recognizes (proto.Primitive, integer-backed refs, etc.). Any other graph.Ref implementation cannot be resolved to stored values, so the store returns this error naming the unexpected value. It signals that a caller passed a Ref produced by a different quadstore or constructed ad hoc.

Source

Thrown at graph/kv/quadstore.go:323

		inds  []int
		irefs []uint64
	)
	for i, v := range vals {
		if v == nil {
			continue
		} else if pv, ok := v.(refs.PreFetchedValue); ok {
			out[i] = pv.NameOf()
			continue
		}
		switch v := v.(type) {
		case Int64Value:
			if v == 0 {
				continue
			}
			inds = append(inds, i)
			irefs = append(irefs, uint64(v))
		default:
			return out, fmt.Errorf("unknown type of graph.Ref; not meant for this quadstore. apparently a %#v", v)
		}
	}
	if len(irefs) == 0 {
		return out, nil
	}
	prim, err := qs.getPrimitives(ctx, irefs)
	if err != nil {
		return out, err
	}
	var last error
	for i, p := range prim {
		if p == nil || !p.IsNode() {
			continue
		}
		qv, err := pquads.UnmarshalValue(p.Value)
		if err != nil {
			last = err
			continue

View on GitHub (pinned to 81dcd7d73e)

Solutions

  1. Only pass graph.Ref values obtained from this same QuadStore instance (e.g. from its iterators or NameOf results)
  2. Convert quad.Value to a store ref via the store's resolution APIs before calling ValuesOf
  3. Check the concrete type of the ref before calling: it must be *proto.Primitive or the integer-ref variants this store emits
  4. Re-create refs after reopening the store instead of persisting them

Example fix

// before
name, err := qs.NameOf(quad.RefOf(quad.IRI("http://example.org/alice")))
// after
refs, err := qs.ValueOf(ctx, quad.IRI("http://example.org/alice"))
if err != nil { return err }
name, err := qs.NameOf(refs)
Defensive patterns

Strategy: type-guard

Validate before calling

func isKVRef(r graph.Ref) bool {
    switch r.(type) {
    case *proto.Primitive:
        return true
    default:
        return false
    }
}

Type guard

func isKVStoreRef(r graph.Ref) bool {
    _, ok := r.(*proto.Primitive)
    return ok
}

Prevention

When it happens

Trigger: Calling QuadStore.NameOf or QuadStore.ValuesOf with a graph.Ref that is not a type this kv quadstore understands (e.g. a *quad.IRI/wrapped ref from another backend, or a BNode ref) instead of the *proto.Primitive refs it returns from its own iterators.

Common situations: Mixing results from two different quadstore backends; caching graph.Ref values across store instances or process restarts where integers were expected; passing literals/IRIs directly instead of resolving them first.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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