使用: "反応-アポロ": "^ 1.4.3"アポロ・クライアント(反応) - 突然変異を作成する上でのアップデート - "フィールドの基金を見つけることができません({})オブジェクト(ROOT_QUERY)の"
親コンポーネントでは、GraphQLを使用して親ノード 'Fund'に子供 'fundQuarterlyMetric'を照会します。これは、次の形式でデータを返します。
{
id
name
...
fundQuarterlyMetrics (orderBy: asAtDate_ASC) {
id
year
quarter
...
}
}
私は更新機能(Apollo Client docs)を使用して反応させ、アポロのローカルストアを更新する必要が新しいfundQuarterlyMetricsを作成しようとします。それは私にエラーを与える:
Can't find field Fund({}) on object (ROOT_QUERY) {
"Fund({\"id\":\"cj57hpfips0x7014414u5tk8m\"})": {
"type": "id",
"id": "Fund:cj57hpfips0x7014414u5tk8m",
"generated": false
}
事が....何をすべきかわからない、私はプロキシをにconsole.logとき、私は基金を見ることができるということであり、それはデータの下の子供..
コメント以下UPDATE:ここ
親成分データ要求である: `
export const fundPageQuery = gql`
query Fund($fundId: ID!) {
Fund(id: $fundId) {
id
name
....other variables
fundQuarterlyMetrics (orderBy: asAtDate_ASC) {
id
year
quarter
....other variables
}
}
} 。
ここで私が使用するオプションは次のとおりです。
var optionsForCreateFundMetric = {
update: (proxy, {data: {createFundMetrics}}) => {
try {
console.log('proxy', proxy);
const data = proxy.readQuery({query: FundQL.fundPageQuery});
console.log('data', data);
data.Fund.fundQuarterlyMetrics.push(createFundMetrics);
proxy.writeQuery({query: FundQL.fundPageQuery, data})
} catch (e) {
console.log('error adding to store', e);
}
} };ここで
export default compose(
graphql(FundQL.createFundMetrics, {name: 'createFundMetrics', options:
optionsForCreateFundMetric}),
graphql(FundQL.updateFundMetrics, {name: 'updateFundMetrics'})
)(FundMetricsForm);
は私の作成突然変異である:
export const createFundMetrics = gql`
mutation createFundQuarterlyMetric(
$fundId: ID
$year: Int!
$quarter: FUND_QUARTERLY_METRIC_QUARTER!
$netIRR: Float!
$tvpi: Float!
$rvpi: Float!
$dpi: Float!
$asAtDate: DateTime
$calledThisQuarter: Float!
$distributedThisQuarter: Float!
$cumulativeCalled: Float!
$cumulativeDistributed: Float!
$limitedPartnersNAV: Float!
$quarterlyValuationChangeLCY: Float
$quarterlyTotalReturn: Float
) {
createFundQuarterlyMetric(
fundId: $fundId
year: $year
quarter: $quarter
netIRR: $netIRR
tvpi: $tvpi
rvpi: $rvpi
dpi: $dpi
asAtDate: $asAtDate
calledThisQuarter: $calledThisQuarter
distributedThisQuarter: $distributedThisQuarter
cumulativeCalled: $cumulativeCalled
cumulativeDistributed: $cumulativeDistributed
limitedPartnersNAV: $limitedPartnersNAV
quarterlyValuationChangeLCY: $quarterlyValuationChangeLCY
quarterlyTotalReturn: $quarterlyTotalReturn
) {
id
year
quarter
netIRR
tvpi
rvpi
dpi
asAtDate
calledThisQuarter
distributedThisQuarter
cumulativeCalled
cumulativeDistributed
limitedPartnersNAV
quarterlyValuationChangeLCY
quarterlyTotalReturn
}
} `;
SOLUTION おかげでダニエル - 私はそれはとてもあなたに感謝動作させるためにファンドのIDを返すために持っていました!
export default compose(
graphql(FundQL.createFundMetrics, {name: 'createFundMetrics', options:
optionsForCreateFundMetric, variables: {fundId:
createFundQuarterlyMetric.fund.id}}),
graphql(FundQL.updateFundMetrics, {name: 'updateFundMetrics'})
)(FundMetricsForm);
ですね - あなたはいけませんあなたが突然変異を扱っているなら、あなたのルートクエリーについてのエラーを見ているでしょう。あなたのコードを含めるためにあなたの質問を更新してください。特に、graphql HOCと関連するロジック( 'update'への呼び出しのような)を定義するところで。 –
ありがとうございました。そしてそれが働いた:> {createFundQuarterlyMetric.fund.id fundId} - ので、私はそれを動作させるためにファンドのIDを返すために持っていた働いていた - 私は疑問に – Blackstone4