Apollo错误:“连接器必须是函数或类”?

时间:2017-08-13 20:08:59

标签: graphql apollo apollostack

我在GraphIQL中有这个查询(注意:Graph I QL)。它给了我一个关于“连接器”的错误消息:

query ($userID: String!) {
  getUserData(id: $userID) {
    name_first
    name_last
    picture_thumbnail
    id
}
}

//query variables:
{
  "userID": "DsmkoaYPeAumREsqC"
}

GraphIQL正在返回此响应:

{
  "data": {
    "getUserData": null
  },
  "errors": [
    {
      "message": "Connector must be a function or an class",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "getUserData"
      ]
    }
  ]
}

这是我的解析器:

getUserData(_, args) {
    debugger;  <== NEVER ACTIVATES
    return Promise.resolve()
        .then(() => {
            console.log('In getUserData');
            var Users = connectors.UserData.findAll({where: args}).then((Users) => Users.map((item) => item.dataValues));
            return Users;
        })
        .then(Users => {
            return Users;
        })
        .catch((err)=> {
            console.log(err);
        });
},

解析器中的debugger断点永远不会激活。

我还不知道“连接器”对GraphIQL的意义。需要改变什么?

1 个答案:

答案 0 :(得分:1)

固定!我必须从connectors的号码中移除对makeExecutableSchema的引用,并将其添加到:

server.use('/graphql', bodyParser.json(), graphqlExpress({
    schema,
    context: {
        connectors: connectors
    }
}));

然后我可以在解析器中检索它,如下所示:

getUserData: (root, args, context) => {
    return Promise.resolve()
        .then(() => {
            var Users = context.connectors.UserData.findAll({where: args}).then((Users) => Users.map((item) => item.dataValues));
            return Users;
        })
        .then(Users => {
            return Users;
        })
        .catch((err)=> {
            console.log(err);
        });
},

感谢Apollo Slack的@marcusnielsen帮我找到了这个提示!