Amplify GraphQL query is success failed to parse

Amplify GraphQL query is success failed to parse


0

I have implemented an GraphQL query using amplify. Query is getting success but response is not getting parsed.

Query Model

static func getStationStateList(deviceUUID:String) -> GraphQLRequest<StationStateList>{

    let operationName = "getStationStateList"
    
    let document = """
    query getStationStateList {
      getStationStateList(DeviceUUID: "(deviceUUID)") {
        items {
          SK
          Data
        }
      }
    }
    """
    return GraphQLRequest<StationStateList>(document: document, responseType: StationStateList.self, decodePath: operationName)
}

Amplify query

@objc func getStationsWateringState(deviceUUID: String){
            
    Amplify.API.query(request: .getStationStateList(deviceUUID: deviceUUID)) { event in
        switch event {
        case .success(let result):
            print("success")
            switch result {
            case .success(let data):
                DispatchQueue.main.sync {
                    print("state: ",data.data.getStationStateList.items)
                }
            case .failure(let error):
                print("Station state query failed with error: (error)")
            }
        case .failure(let error):
            print("Station state query error (error.localizedDescription)")
        }
    }
}

Codable Model structs

struct StationStateList: Codable {
    let data: DataClass
}

struct DataClass: Codable {
    let getStationStateList: GetStationStateList
}

struct GetStationStateList: Codable {
    let items: [Item]?
}

struct Item: Codable {
    let SK : String?
    let Data: String?
}

Response in console

success
Station state query failed with error: GraphQLResponseError<StationStateList>: Failed to decode GraphQL response to the `ResponseType` StationStateList
Recovery suggestion: Failed to transform to `ResponseType`.
Take a look at the `RawGraphQLResponse` and underlying error to see where it failed to decode.
Caused by:
APIError: keyNotFound key CodingKeys(stringValue: "data", intValue: nil)
Caused by:
keyNotFound(CodingKeys(stringValue: "data", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: "data", intValue: nil) ("data").", underlyingError: nil))
error GraphQLResponseError<GetDeviceStateTable>: Failed to decode GraphQL response to the `ResponseType` GetDeviceStateTable
Recovery suggestion: Failed to transform to `ResponseType`.
Take a look at the `RawGraphQLResponse` and underlying error to see where it failed to decode.
Caused by:
APIError: valueNotFound
Caused by:
valueNotFound(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath: [], debugDescription: "Cannot get keyed decoding container -- found null value instead", underlyingError: nil))

Postman

Amplify GraphQL query is success failed to parse


Load 2 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *