我是放大和应用同步的新手。我正在尝试创建一个帖子模型,该模型需要与创建帖子的用户建立关系。问题是我的用户来自认知用户池。
我想要的是来自 cognito 的用户,我不想在 dynamo db 上创建新的用户表,因为 cognito 用户池已经有它的信息,如果我查询帖子,我只想获取正在创建该帖子的用户信息。
我应该如何建立这种关系?
我像这样创建 amlify API
? Please select from one of the below mentioned services: GraphQL
? Choose the default authorization type for the API API key
? Enter a description for the API key:
? After how many days from now the API key should expire (1-365): 7
? Do you want to configure advanced settings for the GraphQL API Yes, I want to make some additional changes.
? Configure additional auth types? Yes
? Choose the additional authorization types you want to configure for the API Amazon Cognito User Pool
Cognito UserPool configuration
Use a Cognito user pool configured as a part of this project.
? Configure conflict detection? No
这是我当前的模式.grapql
type Post
@model
@versioned
@aws_cognito_user_pools
@auth(rules: [{ allow: owner, queries: null }, { allow: public }]) {
id: ID!
title: String!
content: String
thumb: String
slug: String!
allow_comments: Boolean
owner: String!
post_type: String!
add_to_nav: Boolean!
version: Int!
comments: [Comment] @connection(name: "PostComments")
}
type Comment
@model
@versioned
@aws_cognito_user_pools
@auth(rules: [{ allow: owner, queries: null }]) {
id: ID!
content: String
version: Int!
post: Post @connection(name: "PostComments")
}
====
======================================================编辑:添加了我想要的数据的结果
这是我要执行的查询
query ListPost {
listPosts {
items {
title
content
owner{
username
id
email
first_name
last_name
}
}
}
}
}
我想要的结果
{
"data": {
"listPosts": {
"items": [
{
"title": "title 1"
"content": "Test long text cotent"
"owner": {
"username": "user1"
"id": "234234234"
"email": "user1@test.com"
"first_name": "John"
"last_name": "Doe"
}
},
{
"title": "title 1"
"content": "Test long text cotent"
"owner": {
"username": "user1"
"id": "234234234"
"email": "user1@test.com"
"first_name": "John"
"last_name": "Doe"
}
},
]
}
}
}
我找不到任何如何构建这样的东西的文档。
这应该对正在考虑这样做的任何其他人有所帮助:
https://docs.amplify.aws/cli-legacy/graphql-transformer/function/#usage
滚动到:
示例:从 Amazon Cognito 用户池获取登录用户