[英]Variable ID! remains undefined in graphql mutation
I have mutations - 我有突变-
`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
}
}
};`
and a function which looks like this - 和一个看起来像这样的功能-
`this.props.createTimeLine().then((response) => {
console.log(response.data.createTimeLine.id);
this.addTimeLineToUser(response.data.createTimeLine.id, this.props.userQuery.user.id);
});`
user has a one -to one relations like this - 用户具有这样的一对一关系-
`setTimeLineOnUser(userTimeLineId: ID!, timeLineUserId: ID!): SetTimeLineOnUserPayload`
now on running i get this error - 现在运行我得到这个错误-
Error: GraphQL error: Variable '$tID' expected value of type 'ID!'
错误:GraphQL错误:类型“ ID!”的变量“ $ tID”期望值 but value is undefined.
但值未定义。 Reason: Expected non-null value, found null.
原因:预期的非空值,发现为空。 (line 1, column 11): mutation ($tID: ID!, $uID: ID!) { ^ GraphQL error: Variable '$uID' expected value of type 'ID!'
(第1行,第11列):突变($ tID:ID !, $ uID:ID!){^ GraphQL错误:类型为'ID!'的变量'$ uID'期望值 but value is undefined.
但值未定义。 Reason: Expected non-null value, found null.
原因:预期的非空值,发现为空。 (line 1, column 22): mutation ($tID: ID!, $uID: ID!) { ^ at new ApolloError (apollo.umd.js:1959) at apollo.umd.js:2670 at tryCallOne (core.js:37) at core.js:123 at JSTimers.js:117 at Object.callTimer (JSTimersExecution.js:95) at Object.callImmediatesPass (JSTimersExecution.js:199) at Object.callImmediates (JSTimersExecution.js:214) at MessageQueue.js:228 at MessageQueue.__guard (MessageQueue.js:218)
(第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)
although console.log(this.props.userQuery.user.id);
虽然
console.log(this.props.userQuery.user.id);
is returning valid ID! 正在返回有效的ID! I even tried to make the mutation assigning the ids to states so that they may not be null but still no use!!!
我什至试图使将ID分配给状态的变异,以使它们可能不为null,但仍然没有用! what I am doing wrong?
我做错了什么?
if you want to see the files go here - Gist 如果您想查看文件,请在此处-Gist
The problem is when you call the addTimelineToUser
you give an object but you need both parameters. 问题是,当您调用
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); }); };
And it might be that this does not work because im not sure if the query is loaded inside the component did mount function. 可能这是行不通的,因为我不确定该查询是否在组件内部加载了,但确实执行了挂载功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.