首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可变ID!在graphql突变中仍未定义

问可变ID!在graphql突变中仍未定义
EN

Stack Overflow用户
提问于 2017-05-13 11:44:24
回答 1查看 1.1K关注 0票数 0

我有突变-

代码语言:javascript
复制
`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
            }
        }
    };`

一个像这样的函数-

代码语言:javascript
复制
`this.props.createTimeLine().then((response) => {
            console.log(response.data.createTimeLine.id);
            this.addTimeLineToUser(response.data.createTimeLine.id, this.props.userQuery.user.id);
        });`

用户有一个像这样的一个-to one关系-

代码语言:javascript
复制
`setTimeLineOnUser(userTimeLineId: ID!, timeLineUserId: ID!): SetTimeLineOnUserPayload`

我在跑步的时候发现了这个错误-

错误: GraphQL错误:变量'$tID‘类型的期望值'ID!’但是价值是没有定义的。原因:预期为非空值,发现为空.(第1行,第11列):突变($tID: ID!,$uID: ID!) {^ GraphQL错误:变量'$uID‘类型的期望值'ID!’但是价值是没有定义的。原因:预期为非空值,发现为空.(第1行,第22栏):突变($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)在MessageQueue.js:228 at MessageQueue.__guard (MessageQueue.js:218)

尽管console.log(this.props.userQuery.user.id);正在返回有效的ID!我甚至尝试进行变异,将I分配给状态,这样它们可能不是空的,但仍然没有用!我做错什么了?

如果你想看到文件在这里- 要旨

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-13 12:23:44

问题是,当您调用addTimelineToUser时,您会给出一个对象,但是您需要这两个参数。

​

代码语言:javascript
复制
    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);
        });
    };

​

这可能不起作用,因为我不确定查询是否加载在组件中,因此挂载函数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43952752

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档