class GraphExtractionWriter implements ResultDataContentWriter {

    @Override
    public void write( JsonGenerator out, Iterable<String> columns, Result.ResultRow row,
            TransactionStateChecker txStateChecker ) throws IOException
    {
        Set<Node> nodes = new HashSet<>();
        Set<Relationship> relationships = new HashSet<>();
        extract( nodes, relationships, map( columns, row ) );

        out.writeObjectFieldStart( "graph" );
        try
        {
            writeNodes( out, nodes, txStateChecker );
            writeRelationships( out, relationships, txStateChecker );
        }
        finally
        {
            out.writeEndObject();
        }
    }

}