使用iOS SDK时无法启动我的AWS AppSync订阅。我已经成功运行了Mutations and Queries,因此我不确定订阅可能会做错什么。
我的AppSync GraphQL架构。我已经确认所有这些都可以在AWS AppSync控制台中正常工作。
type Mutation {
updateState(id: ID!, state: State!): StateChange
}
type Subscription {
watchState(id: ID!): StateChange
@aws_subscribe(mutations: ["updateState"])
}
type StateChange {
id: ID!
state: State!
}
enum State {
regular
lockdown
accolades
}
我的iOS代码:
//Set a variable to discard at the class level
var discard: Cancellable?
//In your app code
do {
discard = try appSyncClient?.subscribe(subscription: WatchStateSubscription(id: "20"),
resultHandler: { (result, transaction, error) in
print("SUBSCRIPTION TRIGGERED")
if let result = result {
print("RESULT")
print(result.data!.watchState!.state)
} else if let error = error {
print("ERROR")
print(error.localizedDescription)
}
})
} catch {
print("Error starting subscription.")
}
我可以根据需要提供其他详细信息!我的“ SUBSCRIPTION TRIGGERED”打印声明从不打印,即使我通过AppSync控制台发送了成功更改“状态”数据的Mutation。