【发布时间】:2021-08-11 23:25:49
【问题描述】:
我有一个自定义 GraphQL 架构,用于我的 ReactJS 应用程序的博客应用程序。主要模型类型为 Post。
Post 包含许多具有自定义类型的属性,例如 Gallery: [MediaObject]。 AWS Amplify CLI 自动生成的 CreatePostInput 中缺少大多数具有自定义类型的属性。这意味着我无法创建具有自定义类型的这些属性的 Post 对象。
这些自定义类型属性的缺失在 AppSync 控制台的查询下很明显。在资源管理器中,转到 Mutations,单击 CreatePost 突变,您将看到 Post 的 21 个属性中有 6 个丢失。缺少的属性是标签、属性、seo、featuredImage、gallery 和 createdBy。
react 应用程序的 api > build > schema.graphql 中自动生成的 graphql 架构中也缺少它们。
我从头开始做了多个干净的项目,问题是可重现的。我已将放大 cli 更新到 4.51.2,但仍然没有运气。
我希望 CreatePostInput 具有所有字段的关联输入,而不仅仅是 comments(请参阅下面的自动生成的 CreatePostInput),例如:attribute: 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),可在 amplify > backend > api > build > schema.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
}
【问题讨论】:
标签: reactjs amazon-web-services graphql aws-amplify