[英]AWS Amplify API error - field is not of type Int
I'm trying to push my AWS Amplify API schema/create the resource but it errors out saying:我正在尝试推送我的 AWS Amplify API 架构/创建资源,但它错误地说:
✖ An error occurred when pushing the resources to the cloud
managerId field is not of type Int
The error goes away if I change managerId to an Int on the Writer type but I don't want to do that.如果我将 Writer 类型的 managerId 更改为 Int,错误就会消失,但我不想这样做。 It should be an ID.
应该是身份证。 Any idea what's wrong here?
知道这里有什么问题吗?
schema.graphql模式.graphql
type Writer implements Person
@model
@searchable
@key(name: "byManager", fields: ["managerId", "hourlyPay"])
@auth(rules: [
{allow: groups, groups: ["Admin"]},
{allow: public, provider: iam, operations: [read]}
])
{
id: ID!
managerId: ID!
name: String!
hourlyPay: Float!
manager: Manager! @connection(fields: ["managerId"])
}
type Manager implements Person
@model
@searchable
@auth(rules: [
{allow: groups, groups: ["Admin"]},
{allow: public, provider: iam, operations: [read]}
])
{
id: ID!
name: String!
department: String
writers: [Writer!]! @connection(keyName: "byManager", fields: ["id"])
}
Thanks!谢谢!
I had the same issue in an Android project I was working on.我在我正在处理的 Android 项目中遇到了同样的问题。
I fixed it by placing the next code in a file I created under app/src/main/graphql
(I had to create the folder graphql).我通过将下一个代码放在我在
app/src/main/graphql
下创建的文件中来app/src/main/graphql
(我必须创建文件夹 graphql)。
/app/src/main/graphql/aws-directives.graphql /app/src/main/graphql/aws-directives.graphql
directive @connection(name: String, keyField: String, sortField: String, limit: Int) on FIELD_DEFINITION
Then, instead of using @key I only used the directive @connection like this然后,我没有使用 @key 而只是使用了这样的指令 @connection
type Comment @model {
id: ID!
text: String!
postId: Post @connection(name: "commentsByPost")
}
type Post @model {
id: ID!
comments: [Comment] @connection(name: "commentsByPost")
}
Finally when you create comments you have to pass the postId.最后,当您创建评论时,您必须传递 postId。 If you do a query to list the Posts and its comments you will get the comments associated with each post correctly.
如果您进行查询以列出帖子及其评论,您将正确获得与每个帖子相关联的评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.