SwiftData fetch request publisher returns only one value

I am using repository pattern in my app so the repository has such a function:

func getAll() throws -> some Publisher<[CryptoPrice], Never> {
        
        let descriptor = FetchDescriptor<CryptoPriceDbEntity>()
        
        let testPublisher = try context.fetch(descriptor)
            .publisher
            .print()
            .map { dbEntity in
                CryptoPriceMapper.mapFromDbEntity(dbEntity)
            }
            .collect()
            .print()
            .eraseToAnyPublisher()
        //FIXME: this publisher send one value and then close. Is it normal behaviour of swift Data
        return testPublisher
    }

and the view model subscribe to this. I was expecting the view model to receive the new query result whenever it the database changes as a constant stream. But I was surprised to see the publisher send some data once and then it close immediately.

Is it normal behaviour of SwiftData or is there a big in this code ?

the publisher you are using is a publisher that the type [CryptoPriceDbEntity] exposes, therefor it is unaware of data changes in SwiftData.

SwiftData fetch request publisher returns only one value
 
 
Q