dgraph-io/dgraph · error

Unknown value type for nquad: %+v

Error message

Unknown value type for nquad: %+v

What it means

ToEdgeUsing switches on nq.valueType() to decide whether to build a UID edge or a value edge. If the N-Quad's value type is none of the known kinds (ValueUid, ValuePlain, ValueMulti), the library cannot represent it as an edge and returns this error from the default branch.

Source

Thrown at dql/mutation.go:194

	if sUid == 0 {
		return nil, errors.Errorf("Subject should be > 0 for nquad: %+v", nq)
	}

	switch nq.valueType() {
	case x.ValueUid:
		oUid, err := toUid(nq.ObjectId, newToUid)
		if err != nil {
			return nil, err
		}
		if oUid == 0 {
			return nil, errors.Errorf("ObjectId should be > 0 for nquad: %+v", nq)
		}
		edge = nq.CreateUidEdge(sUid, oUid)
	case x.ValuePlain, x.ValueMulti:
		edge, err = nq.CreateValueEdge(sUid)
	default:
		return &emptyEdge, errors.Errorf("Unknown value type for nquad: %+v", nq)
	}
	if err != nil {
		return nil, err
	}
	return edge, nil
}

func copyValue(out *pb.DirectedEdge, nq NQuad) error {
	var err error
	var t types.TypeID
	if out.Value, t, err = byteVal(nq); err != nil {
		return err
	}
	out.ValueType = t.Enum()
	return nil
}

func (nq NQuad) valueType() x.ValueTypeInfo {

View on GitHub (pinned to 759e242be6)

Solutions

  1. Build N-Quads via the RDF parser instead of hand-filling api.NQuad so ValueType is derived correctly
  2. Print the offending nquad (%+v) and check its ValueType/ObjectValue fields against the supported x.Value* constants
  3. Upgrade/align client and server versions so the ValueType enum matches what dql supports
  4. If the value is a literal, ensure ObjectId is set (not empty) so valueType() classifies it as ValuePlain

Example fix

// before
nq := api.NQuad{Subject: "0x1", Predicate: "name"} // no object/value set
// after
nq := api.NQuad{Subject: "0x1", Predicate: "name", ObjectId: "0x2"}
Defensive patterns

Strategy: validation

Validate before calling

func knownValueType(nq *api.NQuad) bool {
  switch nq.ValueType {
  case api.NQuad_VALUE_UID, api.NQuad_VALUE_STRING, api.NQuad_VALUE_DATETIME, api.NQuad_VALUE_INT, api.NQuad_VALUE_FLOAT, api.NQuad_VALUE_BOOL:
    return true
  }
  return nq.ObjectId != "" || nq.ObjectValue != nil
}

Prevention

When it happens

Trigger: Passing a malformed or programmatically constructed api.NQuad to ToEdgeUsing whose ObjectId/value encoding does not map to any known ValueType — e.g. an NQuad built by hand with an unset or unsupported ValueType field.

Common situations: Constructing api.NQuad structs in Go instead of parsing RDF text (parser normally sets ValueType); version drift where a ValueType enum value isn't handled by this Dgraph version; corrupted intermediate representations from custom tooling.

Related errors


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