变量标识!在 graphql 突变中仍未定义

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`

现在 运行 我收到这个错误 -

Error: GraphQL error: Variable '$tID' expected value of type 'ID!' 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!' 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)

尽管 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);
        });
    };

这可能是行不通的,因为我不确定查询是否加载到组件内部并执行挂载功能。