gpt4 book ai didi

reactjs - React-Apollo Mutation 返回空响应

转载 作者:行者123 更新时间:2023-12-03 13:22:38 28 4
gpt4 key购买 nike

我正在使用 AWS Appsync,希望从成功执行的突变中获取响应。当我在 Appsync Graphql 控制台中尝试设置时,我收到填充的 "data": { "mutateMeeting"} 响应: Appsync mutation

当我在 React 应用程序中尝试相同的操作时,我可以在 dynamodb 数据库中看到突变发生,但 react-apollo 不会返回突变响应。正如您在 apollo 开发工具中看到的,"data": { "mutateMeeting"}null : enter image description here

我错过了什么?

相应的graphql schema读取:

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-tag 突变内容如下:

import gql from 'graphql-tag'

export default gql`
mutation mutateMeeting($companyId: String!, $meeting: MeetingInput!) {
mutateMeeting(companyId: $companyId, meeting: $meeting) {
id,
start,
end
}
}
`

并且 react-apollo 暗示由以下给出:

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)
}
}

Appsync 响应:

#set( $meeting = $context.result.data.Vysae[1] )
{
"id": "$meeting.PK",
"start": "$meeting.start",
"end": "$meeting.end"
}

最佳答案

看起来此错误有一个 Unresolved 问题 herethis original issue中有更多详细信息也是如此。

The user information in the SessionQuery will initially be cached and watched by the UserProfile component. When the UpdateAvatarMutation executes and returns, the query in the UserProfile component will receive empty data. Several others have also observed this behavior and all traced it to an imperfect overlap between the queried/cached fields and the fields returned on the mutation (in this example, email is missing from the User node on the mutation's returned results.

换句话说,如果您的查询返回相同类型的对象,并且查询和突变之间的字段不匹配,则最终可能会得到空数据。这不是预期的行为,但如果这是这种情况下的根本问题,您可以尝试确保查询和突变的请求字段相同。

关于reactjs - React-Apollo Mutation 返回空响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51935902/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com