0

我想设置“移动”的实时列表列表,所以我使用了放大文档中的这个片段。

 func createSubscription() {
        subscription = Amplify.API.subscribe(request: .subscription(of: Move.self, type: .onCreate))
        dataSink = subscription?.subscriptionDataPublisher.sink {
            if case let .failure(apiError) = $0 {
                print("Subscription has terminated with \(apiError)")
            } else {
                print("Subscription has been closed successfully")
            }
        }
        receiveValue: { result in
            switch result {
            case .success(let createdTodo):
                print("Successfully got todo from subscription: \(createdTodo)")
            case .failure(let error):
                print("Got failed result with \(error.errorDescription)")
            }
        }
    }

架构身份验证规则

type Move 
  @model 
  @auth( rules: [
    { allow: owner, ownerField: "owner", operations: [create, update, delete, read] },
  ]) 
{

但是由于我将身份验证添加到“移动”类型,所以我收到了这个错误。GraphQLResponseError<Move>: GraphQL service returned a successful response containing errors: [Amplify.GraphQLError(message: "Validation error of type MissingFieldArgument: Missing field argument owner @ \'onCreateMove\'", locations: nil, path: nil, extensions: nil)]

Recovery suggestion: The list of GraphQLError contains service-specific messages

所以一切都在本地工作,但我认为我需要将授权传递给请求,但我找不到任何方法来做到这一点。有什么想法可以让我正确处理这个请求吗?

4

1 回答 1

0

通过编写我自己的请求并直接传递所有者字段使其工作

extension GraphQLRequest {
    static func newMoves() -> GraphQLRequest<Move> {
        let operationName = "getMove"
        let document = """
        subscription MySubscription {
          onCreateMove(owner: "MyUser") {
            accerationMagnitude
            id
          }
        }

        """
        return GraphQLRequest<Move>(document: document,
//                                    variables: [],
                                    responseType: Move.self,
                                    decodePath: operationName)
    }
}
于 2021-03-14T18:08:46.667 回答