     public func load<S: Sequence>(version: Version, quads: S) throws where S.Iterator.Element == Quad {
         self.version = version
         let idq = quads.map { idquad(from: $0) }
+        let graphs = Set(idq.map { $0.graph })
         self.count += idq.count
+        for g in graphs {
+            self.graphIDs.insert(g)
+        }
         self.idquads.append(contentsOf: idq)
     }
 }

    var t2i: [Term: TermID]
    var version: Version?
    var next: TermID
    
    public init(version: Version? = nil) {
        self.next = 1

        self.idquads = []
        self.i2t = [:]
        self.t2i = [:]
        self.graphIDs = []
        self.version = version
    }
    
    public func graphs() -> AnyIterator<Term> {
        let graphs = graphIDs.map { i2t[$0]! }
        return AnyIterator(graphs.makeIterator())
    }
    
