[英]Variable ID! remains undefined in graphql mutation
我有突變-
`export const setTimeLineOnUser = gql
mutation ($tID: ID!, $uID: ID! ){
setTimeLineOnUser(userTimeLineId: $tID, timeLineUserId: $uID){
userTimeLine {
id
updatedAt
posts{
id
postType
updatedAt
}
}
timeLineUser {
id
name
email
}
}
};`
和一個看起來像這樣的功能-
`this.props.createTimeLine().then((response) => {
console.log(response.data.createTimeLine.id);
this.addTimeLineToUser(response.data.createTimeLine.id, this.props.userQuery.user.id);
});`
用戶具有這樣的一對一關系-
`setTimeLineOnUser(userTimeLineId: ID!, timeLineUserId: ID!): SetTimeLineOnUserPayload`
現在運行我得到這個錯誤-
錯誤:GraphQL錯誤:類型“ ID!”的變量“ $ tID”期望值 但值未定義。 原因:預期的非空值,發現為空。 (第1行,第11列):突變($ tID:ID !, $ uID:ID!){^ GraphQL錯誤:類型為'ID!'的變量'$ uID'期望值 但值未定義。 原因:預期的非空值,發現為空。 (第1行,第22列):變異($ tID:ID !, $ uID:ID!){^在new ApolloError(apollo.umd.js:1959)在apollo.umd.js:2670在tryCallOne(core.js) :37)在core.js:123在JSTimers.js:117在Object.callTimer(JSTimersExecution.js:95)在Object.callImmediatesPass(JSTimersExecution.js:199)在Message.Queue的Object.callImmediates(JSTimersExecution.js:214) .js:228位於MessageQueue .__ guard(MessageQueue.js:218)
雖然console.log(this.props.userQuery.user.id);
正在返回有效的ID! 我什至試圖使將ID分配給狀態的變異,以使它們可能不為null,但仍然沒有用! 我做錯了什么?
如果您想查看文件,請在此處-Gist
問題是,當您調用addTimelineToUser
您提供了一個對象,但同時需要兩個參數。
componentDidMount(){ this.props.createTimeLine().then((response) => { // this.addTimeLineToUser({ tID: response.data.createTimeLine.id, uID: this.props.userQuery.user.id }) wrong this.addTimeLineToUser(response.data.createTimeLine.id, this.props.userQuery.user.id) }); } addTimeLineToUser = (tId, uId) => { this.props.setTimeLineOnUser({variables: {tId, uId}}) .then((response) => { console.log(response); }).catch((err) => { console.log(err); }); };
可能這是行不通的,因為我不確定該查詢是否在組件內部加載了,但確實執行了掛載功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.