I'm trying to use a grapghQL API to query a list of data and return an array of that data. From that array, I will pick one random value to use. The code looks as follows:
func queryLyrics() { var lyricArray : [Lyric] = [] Task { do { let result = try await Amplify.API.query(request: .list(Transaction.self))
switch result {
case .success(let lyricsData):
print("Successfully retrieved list of Lyrics")
// convert an array of LyricData to an array of Lyric class instances
//an array of LyricData to get one Lyric class instance
for n in lyricsData {
let lyric1 = Lyric.init(from: n)
MainActor.run {
lyricArray.append(lyric1)
}
}
let goodLyric = lyricArray.randomElement()
case .failure(let error):
print("Can not retrieve result : error \(error.errorDescription)")
}
} catch {
print("Can not retrieve Notes : error \(error)")
}
}
}.
However, the .list function provides the error: Static method 'list(_:where:includes:limit:)' requires that 'Transaction' conform to 'Model'. Im wondering why this is? and how can I fix this?