我正在使用 AWS Appsync,我想从成功执行的突变中获得响应。当我在 Appsync Graphql 控制台中尝试我的设置时,我得到了一个完整的"data": { "mutateMeeting" }
响应:
当我在我的 react 应用程序中尝试相同的操作时,我可以在 dynamodb 数据库中看到,发生了突变,但react-apollo不会返回突变响应。正如您在 apollo 开发工具中看到的,"data": { "mutateMeeting" }
为null:
我错过了什么?
相应的graphql 模式如下:
input MeetingInput {
id: String,
start: String!,
end: String!,
agreements: [AgreementInput]!
}
type Meeting {
id: String!
start: String!
end: String!
agreements: [Agreement]
}
type Mutation {
mutateMeeting (
companyId: String!,
meeting: MeetingInput!
): Meeting!
}
在graphql标签突变写着:
import gql from 'graphql-tag'
export default gql`
mutation mutateMeeting($companyId: String!, $meeting: MeetingInput!) {
mutateMeeting(companyId: $companyId, meeting: $meeting) {
id,
start,
end
}
}
`
和react-阿波罗inklusion由下式给出:
import React, { Component } from 'react'
// antd
import { Spin } from 'antd'
// graphql
import { compose, graphql } from 'react-apollo'
import mutateMeeting from '../queries/mutateMeeting'
class MeetingStatus extends Component {
componentDidMount() {
const { mutateMeeting, meeting } = this.props
console.log(meeting)
const variables = {
companyId: meeting.company.id,
meeting: {
start: meeting.start.toISOString(),
end: meeting.end.toISOString(),
agreements: meeting.agreements,
}
}
console.log(variables)
mutateMeeting({
variables
}).then(({data}) => console.log('got data', data))
.catch(err => console.log(err))
}
render() {
console.log(this.props)
return <div>convocado</div>
}
}
const MeetingStatusWithInfo = compose(
graphql(mutateMeeting, { name: 'mutateMeeting' })
)(MeetingStatus)
export default (MeetingStatusWithInfo)
应用同步请求
#set($uuid = $util.autoId())
#set($batchData = [])
#set( $meeting = ${context.arguments.meeting} )
## Company
#set( $meetingMap = {
"PK" : $context.arguments.companyId,
"SK" : "Meeting-$uuid",
"start" : $meeting.start,
"end" : $meeting.end
} )
$util.qr($batchData.add($util.dynamodb.toMapValues($meetingMap)))
## Meeting
$util.qr($meetingMap.put("PK", $meetingMap.SK))
$util.qr($batchData.add($util.dynamodb.toMapValues($meetingMap)))
## Agreements
#foreach($agreement in $meeting.agreements)
#set( $agreementId = $util.autoId())
#set( $agreementMap = {
"PK" : $meetingMap.SK,
"SK" : "Agreement-$agreementId",
"name" : $agreement.name
} )
$util.qr($batchData.add($util.dynamodb.toMapValues($agreementMap)))
#end
{
"version" : "2018-05-29",
"operation" : "BatchPutItem",
"tables": {
"Vysae": $utils.toJson($batchData)
}
}
应用同步响应:
#set( $meeting = $context.result.data.Vysae[1] )
{
"id": "$meeting.PK",
"start": "$meeting.start",
"end": "$meeting.end"
}