【发布时间】:2017-10-12 15:50:43
【问题描述】:
我有突变 -
`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!){ ^ 在新的 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) 在 Object.callImmediates (JSTimersExecution.js:214) 在 MessageQueue.js:228 在 MessageQueue.__guard (MessageQueue.js:218)
虽然console.log(this.props.userQuery.user.id); 正在返回有效的ID!
我什至试图使突变将 id 分配给状态,以便它们可能不是 null 但仍然没有用!!!我做错了什么?
如果您想查看文件,请点击此处 - Gist
【问题讨论】:
标签: graphql graphql-js apollo react-apollo