Reactjs GraphQL AppSync的自动生成突变输入中缺少对象字段

Reactjs GraphQL AppSync的自动生成突变输入中缺少对象字段,reactjs,amazon-web-services,graphql,aws-amplify,Reactjs,Amazon Web Services,Graphql,Aws Amplify,我的ReactJS应用程序的博客应用程序有一个自定义GraphQL模式。主要型号为Post Post包含许多具有自定义类型的属性,例如Gallery:[MediaObject]。AWS Amplify CLI自动生成的CreatePostInput中缺少大多数具有自定义类型的属性。这意味着我无法创建具有这些自定义类型属性的Post对象 这些自定义类型属性的缺乏在AppSync控制台的“查询”下很明显。在浏览器中,转到突变,单击CreatePost突变,您将看到Post的21个属性中有6个丢失。缺

我的ReactJS应用程序的博客应用程序有一个自定义GraphQL模式。主要型号为Post

Post包含许多具有自定义类型的属性,例如Gallery:[MediaObject]。AWS Amplify CLI自动生成的CreatePostInput中缺少大多数具有自定义类型的属性。这意味着我无法创建具有这些自定义类型属性的Post对象

这些自定义类型属性的缺乏在AppSync控制台的“查询”下很明显。在浏览器中,转到突变,单击CreatePost突变,您将看到Post的21个属性中有6个丢失。缺少的属性有标签、属性、seo、featuredImage、gallery和createdBy

在react应用程序的api>build>schema.graphql中,自动生成的graphql模式中也缺少它们

我从零开始做了多个干净的项目,这个问题是可以重现的。我已将amplify cli更新为4.51.2,但仍然不走运

我希望CreatePostInput具有所有字段的关联输入,而不仅仅是
注释
(请参见下面自动生成的CreatePostInput),例如:
属性:AttributeInput
,但这些也不会生成。这将允许我创建一个填充了这些自定义字段的Post对象。但是,仅生成了
CommentInput
。我做错了什么,或者我误解了什么

谢谢

下面是我的gql模式以及自动生成的CreatePostInput和CommentInput:

type Post @model {
    id: ID
    createdBy: User
    createdAt: AWSDateTime
    updatedAt:AWSDateTime
    type: PostType!
    title: String!
    status: Status
    content: String!
    excerpt: String
    slug: AWSURL
    wordpressId: Int
    wordpressImageURLs: [AWSURL]
    author: String
    likes: Int
    tags: [Tag]
    attributes: Attribute
    seo: Seo
    featuredImage: MediaObject
    gallery: [MediaObject]
    comments: [Comment]
    numberOfComments: Int

}

type User @model {
    id: ID
    username: String!
    firstName: String
    lastName: String
    email: AWSEmail!
    avatar: MediaObject
    location: String
    createdAt: AWSDateTime
    updatedAt: AWSDateTime
    Posts: [Post]
}

type Tag @model {
    id: ID
    postIds: [ID]
    name: String!
}

type Attribute @model {
    id: ID
    postId: ID
    link: String
    imgUrl: AWSURL
    ogImage: AWSURL
    ogDescription: String
    canonicalLink: AWSURL
}

type Seo @model {
    id: ID
    postId: ID
    metaRobotsNoIndex: String
    metaRobotsNoFollow: String
    canonical: AWSURL
    metaDesc: String
    opengraphDescription: String
    opengraphModifiedTime: AWSDateTime
    opengraphPublishedTime: AWSDateTime
    opengraphTitle: String
    opengraphUrl: AWSURL
    opengraphImage: AWSURL
    twitterDescription: String
    twitterImage: String
    twitterTitle: String
    schemaSeo: String
}

type Comment
   {
  id: ID
  postId: ID!
  createdBy: ID
  author: String
  createdAt: AWSDateTime
  text: String!
  likes: Int
}

type MediaObject @model {
    id: ID
    linkedId: ID
    createdBy: ID
    mediaItemUrl: AWSURL
    srcSet: String
    medium: AWSURL
    thumb: AWSURL
    sourceURL: AWSURL
    description: String
    bucket: String
    region: String
    key: String
    type: MediaObjectType
}

type Like @model {
    id: ID!
    objectVotedOnID: ID!
    createdBy: ID
    createdAt: AWSDateTime
    likeOn: LikeOnType

}

enum PostType {
    TOOLS
    BLOGS
    INSPIRATIONS
    NEWS
    POSTS
    NEWSLETTERS
}

enum LikeOnType {
    POST
    COMMENT
}

enum Status {
    PUBLISH
    DRAFT
}

enum MediaObjectType {
    IMAGE
    VIDEO
    AUDIO
}

自动生成(为简洁起见,仅包含CreatePostInput和CommentInput),可在放大>后端>api>构建>架构.graphql中找到:

input CreatePostInput {
  id: ID
  createdAt: AWSDateTime
  updatedAt: AWSDateTime
  type: PostType!
  title: String!
  status: Status
  content: String!
  excerpt: String
  slug: AWSURL
  wordpressId: Int
  wordpressImageURLs: [AWSURL]
  author: String
  likes: Int
  comments: [CommentInput]
  numberOfComments: Int
}

input CommentInput {
  id: ID
  postId: ID!
  createdBy: ID
  author: String
  createdAt: AWSDateTime
  text: String!
  likes: Int
}


至少在您引用的示例中,Post和MediaObject具有一对多关系。也就是说,一篇文章有许多MediaObject。您将看不到在父对象上为突变生成的一对多的多关系

创建具有子对象的父对象时,需要分两步执行

  • 创建父对象,并返回id
  • 使用parentId创建N个子对象

  • 以下是Amplify的一些文档,介绍了如何执行此操作:

    任何注意到这种奇怪行为的人:
    CommentInput
    包含在
    CreatePostInput
    中的原因,而其他自定义类型不包括在内,因为
    Comment
    是我唯一忘记用@model指令标记的类型。我假设这意味着AppSync在
    comments
    字段中将此类型视为一组嵌套字段,而不是具有自己的DynamoDB表的对象。我已经询问了AWS Amplify团队,当我从他们那里得到更多信息时,我会更新这个答案。

    好的,非常感谢您让我知道!知道为什么
    seo
    属性
    featuredImage
    不存在吗?我看不到任何关系被声明。查看并为您的特定用例连接适当的连接/键。好的,谢谢您的指针,但是为什么CreatePostInput(作为CommentInput)中包含comments数组,而其他数组没有?这就是让我困惑的地方:)