Hasura GraphQl在表中存在多个外键时,不会返回所有文档

发布于 2025-01-19 11:42:06 字数 1168 浏览 3 评论 0原文

查询:

user (where: { id: {_eq: 104}}) {
    connections {
      user1
      user2
      status
    }
  }

响应:

{
  "data": {
    "user": [
      {
        "id": 104,
        "connections": [
          {
            "user1": 104,
            "user2": 111,
            "status": "pending"
          }
        ]
      }
    ]
  }
}

预期:

{
  "data": {
    "user": [
      {
        "id": 104,
        "connections": [
          {
            "user1": 104,
            "user2": 111,
            "status": "pending"
          },
          {
            "user1": 96,
            "user2": 104,
            "status": "connected"
          },
          {
            "user1": 112,
            "user2": 104,
            "status": "pending"
          }
        ]
      }
    ]
  }
}

为什么第一个查询中的最后两个文档没有显示?

连接表定义:

CREATE TABLE connections 
(
    id Integer PRIMARY KEY,
    user1 Integer,
    user2 Integer
    FOREIGN KEY (user1) REFERENCES users (id)
    FOREIGN KEY (user2) REFERENCES users (id)
);

我知道这可能更多是一个 SQL 问题,但如果你也能显示 graphql 版本那就太好了

Query:

user (where: { id: {_eq: 104}}) {
    connections {
      user1
      user2
      status
    }
  }

Response:

{
  "data": {
    "user": [
      {
        "id": 104,
        "connections": [
          {
            "user1": 104,
            "user2": 111,
            "status": "pending"
          }
        ]
      }
    ]
  }
}

Expected:

{
  "data": {
    "user": [
      {
        "id": 104,
        "connections": [
          {
            "user1": 104,
            "user2": 111,
            "status": "pending"
          },
          {
            "user1": 96,
            "user2": 104,
            "status": "connected"
          },
          {
            "user1": 112,
            "user2": 104,
            "status": "pending"
          }
        ]
      }
    ]
  }
}

Why are the last two documents not showing up from the first query?

Connection table definition:

CREATE TABLE connections 
(
    id Integer PRIMARY KEY,
    user1 Integer,
    user2 Integer
    FOREIGN KEY (user1) REFERENCES users (id)
    FOREIGN KEY (user2) REFERENCES users (id)
);

I know this could be more of a SQL question, but it would be great if you can show the graphql version too

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墟烟 2025-01-26 11:42:06

您必须在用户表和连接表之间创建两个关系,

然后查​​询:

query MyQuery {
  user(where: {id: {_eq: 104}}) {
    connections {
      user1
      user2
      status
    }
    connectionsByUser2 {
      user1
      user2
      status
    }
  }
}

输出:

You have to create two relationships between users table and connections table,
enter image description here

Then query :

query MyQuery {
  user(where: {id: {_eq: 104}}) {
    connections {
      user1
      user2
      status
    }
    connectionsByUser2 {
      user1
      user2
      status
    }
  }
}

Output:
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文