gpt4 book ai didi

ios - AWS graphql @connection没有按预期返回数组?

转载 作者:行者123 更新时间:2023-12-01 21:58:10 29 4
gpt4 key购买 nike

我有一个graphql模型,如下所示(一个用户可以有很多帖子1:m)

type User @model {
id: ID!
fullName: String!
emailAddress: String!
posts: [Post] @connection(name: "UserPostConnection")
}

type Post @model {
id: ID!
text: String!
user: User @connection(name: "UserPostConnection")
createdAt: String
updatedAt: String
}

我正在尝试返回特定用户的所有帖子,如下所示:
let queryInput = GetUserQuery(id: "879db4f2-1dad-47b9-b70d-8bca15bf2549")

appSyncClient?.fetch(query: queryInput, cachePolicy: .fetchIgnoringCacheData) { (result, error) in
print(result?.data?.getUser?.posts)
}
}

但是结果不是返回数组,而是返回可选的:
Optional(AWSStackSocial.GetUserQuery.Data.GetUser.Post(snapshot: ["__typename": Optional("ModelPostConnection"), "nextToken": nil]))

我已经确认a)用户存在,b)帖子也存在。

在AWS上:
query {
getUser(id: "879db4f2-1dad-47b9-b70d-8bca15bf2549") {
id
posts {
items {
id
}
}
}
}

输出:
{
"data": {
"getUser": {
"id": "879db4f2-1dad-47b9-b70d-8bca15bf2549",
"posts": {
"items": [
{
"id": "04c4b571-6e92-4745-9a40-1a67a9d49d77"
},
{
"id": "0f44fe6e-4e15-4a8c-b591-555e8fa1f60e"
},
{
"id": "60c18c40-fea3-4ff3-8b21-df6857703dd2"
}
]
}
}
}
}

最佳答案

我找到了答案。放大GraphQL的默认深度级别为2,因此需要将其更改为3。这可以通过更改最大深度来完成:

amplify codegen configure

关于ios - AWS graphql @connection没有按预期返回数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60987451/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com