【问题标题】:AWS Amplify API error - field is not of type IntAWS Amplify API 错误 - 字段不是 Int 类型
【发布时间】:2020-05-23 16:38:12
【问题描述】:

我正在尝试推送我的 AWS Amplify API 架构/创建资源,但错误提示:

✖ An error occurred when pushing the resources to the cloud

managerId field is not of type Int

如果我在 Writer 类型上将 managerId 更改为 Int,错误就会消失,但我不想这样做。应该是身份证。知道这里有什么问题吗?

schema.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"])
}

谢谢!

【问题讨论】:

  • 能否将Person接口的定义包含进来看看那里定义了什么

标签: amazon-web-services graphql aws-amplify aws-appsync


【解决方案1】:

我正在处理的一个 Android 项目中遇到了同样的问题。

我通过将下一个代码放在我在app/src/main/graphql 下创建的文件中来修复它(我必须创建文件夹 graphql)。

/app/src/main/graphql/aws-directives.graphql

directive @connection(name: String, keyField: String, sortField: String, limit: Int) on FIELD_DEFINITION

然后,我没有使用@key,而是像这样使用了@connection指令

type Comment @model {
   id: ID!
   text: String!
   postId: Post @connection(name: "commentsByPost")
}


type Post @model {
   id: ID!
   comments: [Comment] @connection(name: "commentsByPost")
}

最后,当您创建 cmets 时,您必须传递 postId。如果您执行查询以列出帖子及其 cmets,您将正确获得与每个帖子关联的 cmets。

【讨论】:

猜你喜欢
  • 2020-05-10
  • 2019-05-12
  • 1970-01-01
  • 1970-01-01
  • 2022-09-27
  • 2018-09-12
  • 1970-01-01
  • 2021-03-19
  • 2020-08-07
相关资源
最近更新 更多