如何从用户池到AWS AppSync模型建立数据关系

时间:2020-01-23 05:49:58

标签: amazon-cognito aws-amplify aws-appsync

我是新手,无法进行放大和appsync。我正在尝试创建一个Post模型,该模型需要与正在创建Post的用户建立关系。问题是我的用户来自cognito用户池。

我想要的是cognito的用户,我不想在dynamo db上创建新的用户表,因为cognito用户池已经具有其信息,我只想获取创建该Post的用户信息(如果我查询该帖子)

我应该如何建立这种关系?

我这样创建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"
           }
        },
      ]
    }
  }
}

我找不到任何文档来构建这样的东西。

0 个答案:

没有答案