【问题标题】:Issues joining tables in GraphQL resolvers, thrown 400 error在 GraphQL 解析器中加入表时出现问题,抛出 400 错误
【发布时间】:2019-11-04 04:56:18
【问题描述】:

我正在尝试使用 GraphQL 加入 MySQL 表并不断收到 400 错误代码:

"Response not successful: Received status code 400"

这就是我查询数据的方式:

{
  users {
    usr_last_name
    business {
      bus_name
    }
  }
}
# or
{
  user(usr_id:1) {
    usr_last_name
    business {
      bus_name
    }
  }
}

这是User 的解析器。

export const resolvers = {
    Query: {
        users: async() => db.user.findAll(),
        user: async(obj, args, context, info) => db.user.findByPk(args.usr_id)
    },
    Mutation: {...},
    User: {
        business: async(obj, args, context, info) => {  // This is not getting hit :/ 
           return db.business.findAll({where: {bus_user_id: args.usr_id}});
        }
    }
};

(请注意,我可以毫无问题地查询Business

谢谢,

【问题讨论】:

  • 400 状态通常意味着您的查询格式错误或无效。检查来自服务器的实际响应中的errors 数组,了解有关问题的详细信息。
  • @DanielRearden 没有太多信息,只是“回复不成功”:{ "errors": [ { "message": "Response not successful: Received status code 400", "locations": [ "ServerError: Response not successful: Received status code 400 at throwServerError (http://localhost:5001/static/js/0.chunk.js:396952:15) at http://localhost:5001/static/js/0.chunk.js:396975:9" ] } ] }
  • 你在做SSR吗?您可以通过 GraphQL Playground 运行相同的查询以获取实际错误。
  • 我只是这样做了,发现它提供了额外的信息。谢谢:),现在解决了。

标签: javascript graphql apollo-server


【解决方案1】:

问题是我忘记在类型用户的类型定义中输入business: Business

    type User {
        usr_id: ID
        usr_first_name: String
        usr_last_name: String
        usr_email: String
        usr_password: String
        usr_create_date: Int
        usr_delete_date: Int,
        business: Business
    }

【讨论】:

    猜你喜欢
    • 2019-01-02
    • 2017-05-07
    • 1970-01-01
    • 2019-11-05
    • 2018-06-15
    • 2018-03-23
    • 1970-01-01
    • 2017-07-15
    • 2014-08-12
    相关资源
    最近更新 更多