无法将参数传递给阿波罗中的查询

时间:2018-11-12 11:39:38

标签: node.js graphql apollo react-apollo

我在这里有一个有效的查询

 const getCicadaByUserIdQuery = gql`
 query($id:String){
  user(id:$id){
    id
    userName
    password
      cicadas {
        name
        id
        image
        long
        lat
        userid
      }
  }
}`

在本地主机中传递有效的用户ID时,它将按预期返回数据。 我想做的是在登录的用户上传递特定用户的参数

export default compose(
 graphql(getCicadasQuery,{name:"getCicadasQuery"}),
 graphql(addCicadaMutation,{name:"addCicadaMutation"}),
 graphql(getCicadaByUserIdQuery,{
    name:"getCicadaByUserIdQuery",
    options: () => ({ variables: { id: getLoginUser().id } })

 }),
 graphql(getUsersQuery,{name:"getUsersQuery"}),
)(CicadaScoutScreen)

getLoginUser()是一个简单函数,可返回当前登录用户的数据。

然后我通过以下方式调用此查询:

this.props.getCicadaByUserIdQuery

请帮助我似乎无法使其正常工作

1 个答案:

答案 0 :(得分:0)

如果它可以与localhost一起使用,但不能在运行的服务器上使用,则可能与getLoginUser()函数的工作方式有关。

您可以console.log该函数的输出进行调试,如下所示: graphql(getCicadaByUserIdQuery,{ name:"getCicadaByUserIdQuery", options: () => { console.log(getLoginUser()); return { variables: { id: getLoginUser().id } }; } }),

如果它在localhost中工作,那么Apollo Client本身可能就不是问题。

相关问题