【发布时间】:2021-06-16 07:28:42
【问题描述】:
我们目前正在研究堆栈:cdk、appsync 和 amplify 以迁移我们的应用程序。
在我们最初的测试中,我们能够上传一个只有 appsync 和 wit 关系的 graphql api,它非常流畅、漂亮和快速。
在测试使用 cdk 构建时,我们很难创建关系。
这是我的代码:
架构
type Person {
id: ID!
name: String!
}
input PersonInput {
id: ID!
name: String!
}
input UpdatePersonInput {
id: ID!
name: String
}
type Client {
id: ID!
type: String!
personId: String
# Person: PersonConnection
Person: Person @connection(fields: ["personId"])
}
input ClientInput {
id: ID!
type: String!
personId: String!
}
input UpdateClientInput {
id: ID!
type: String
personId: String
}
我的功能
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient();
async function list() {
const params = {
TableName: process.env.CLIENT_TABLE,
}
try {
const data = await docClient.scan(params).promise()
return data.Items
} catch (err) {
console.log('DynamoDB error: ', err)
return null
}
}
export default list;
我的桌子
const clientTable = new dynamodb.Table(scope, 'ClientTable', {
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
partitionKey: {
name: 'id',
type: dynamodb.AttributeType.STRING,
},
});
clientTable.addGlobalSecondaryIndex({
indexName: 'client-by-person-id',
partitionKey: {
name: 'personId',
type: dynamodb.AttributeType.STRING
},
sortKey: {
name: 'createdAt',
type: dynamodb.AttributeType.STRING
}
})
我的查询
query MyQuery {
listClients {
id
personId
type
Person {
name
}
}
}
但是,我返回的 Person 连接是 null
"listClients": [
{
"id": "1",
"personId": "1",
"type": "PJ",
"Person": null
}
]
如果能指出我们的错误,我将不胜感激
【问题讨论】:
标签: graphql aws-appsync aws-cdk