首页 > 解决方案 > 配置 Amplify 以允许 API 中的动态属性

问题描述

我有一个应用程序,用户从 UI 将 .json 文件上传到 S3。

假设一个用户上传了一个 .json 文件,代表人们在此处输入代码:

[
  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "Sincere@april.biz",
    "address": {
      "street": "Kulas Light",
      "suite": "Apt. 556",
      "city": "Gwenborough",
      "zipcode": "92998-3874",
      "geo": {
        "lat": "-37.3159",
        "lng": "81.1496"
      }
    },
    "phone": "1-770-736-8031 x56442",
    "website": "hildegard.org",
    "company": {
      "name": "Romaguera-Crona",
      "catchPhrase": "Multi-layered client-server neural-net",
      "bs": "harness real-time e-markets"
    }
  },
  {
    "id": 2,
    "name": "Ervin Howell",
    "username": "Antonette",
    "email": "Shanna@melissa.tv",
    "address": {
      "street": "Victor Plains",
      "suite": "Suite 879",
      "city": "Wisokyburgh",
      "zipcode": "90566-7771",
      "geo": {
        "lat": "-43.9509",
        "lng": "-34.4618"
      }
    },
    "phone": "010-692-6593 x09125",
    "website": "anastasia.net",
    "company": {
      "name": "Deckow-Crist",
      "catchPhrase": "Proactive didactic contingency",
      "bs": "synergize scalable supply-chains"
    }
  }
.
.
.
]

另一个用户上传了一个代表完全不同对象的 .json 文件,比如说一个待办事项列表:

  {
    "userId": 1,
    "id": 1,
    "title": "delectus aut autem",
    "completed": false
  },
  {
    "userId": 1,
    "id": 2,
    "title": "quis ut nam facilis et officia qui",
    "completed": false
  },
  {
    "userId": 1,
    "id": 3,
    "title": "fugiat veniam minus",
    "completed": false
  }
.
.
]

我想获取这个上传文件的内容,并将它们存储在 DynamoDB(通过 Amplify)中,以便用户可以在 UI 上查询/过滤对象。现在,我必须向 Amplify 提供静态属性列表以生成 API。鉴于此,我将如何修改 Amplify 生成的 schema.graphql 文件以允许动态属性?

标签: graphqlnosqlamazon-dynamodbaws-amplifynon-relational-database

解决方案


推荐阅读