使用连接类型获取GraphQL查询

时间:2019-04-03 15:36:44

标签: ios swift amazon-web-services

我有一个连接到AWS Appsync API的ios应用程序。我的GraphQL模式包含的模型包含与其他模型的连接。我的俱乐部模型包含一系列餐厅模型(请参见下面的代码)。

我可以成功运行一个查询,该查询在AppSync控制台中返回一组餐厅。但是,当我通过ios中的Appsync运行ListClubs查询时,餐厅字段将返回连接类型,而不是餐厅对象的预期数组

//GraphQL schema definition
type Club @model {
  id: ID!
  name: String!
  address_1: String!
  address_2: String
  city: String!
  state: String!
  zipcode: String!
  phone: String!
  search_name: String!
 restaurants: [Restaurant] @connection(name: "Restaurants")
}
type Restaurant @model {
 id: ID!
 name: String!
 club: Club @connection(name: "Restaurants")
 menus: [Menu] @connection(name: "Menus")
}

//My IOS Code
appSyncClient?.fetch(query: ListClubsQuery(filter : filterInput ), cachePolicy: .fetchIgnoringCacheData) { (result, error) in
        if error != nil {
            print(error?.localizedDescription ?? "")
            return
        }



        self.clubs = result?.data?.listClubs?.items
        self.clubListVC?.updateClubList(clubs: (self.clubs! as? [ListClubsQuery.Data.ListClub.Item])!)


        for club in self.clubs! {
            print(club?.restaurants)
        }
...

期望:俱乐部?餐厅是与特定俱乐部相​​关的一系列餐馆

结果(在ios调试器中):可选(Divot_Mobile_App.ListClubsQuery.Data.ListClub.Item.Restaurant(快照:[“ nextToken”:零,“ __ typename”:可选(“ ModelRestaurantConnection”)]))))

0 个答案:

没有答案