GraphQL缝合和结合

问题描述 投票:0回答:1

我需要将多个具有相同架构的graphQl服务'聚合'到单个只读(仅查询)服务中,以暴露来自所有服务的数据。例如:

---- domain 1 ----
    "posts": [
      {
        "title": "Domain 1 - First post",
        "description": "Content of the first post"
      },
      {
        "title": "Domain 1 - Second post",
        "description": "Content of the second post"
      }
    ]

---- domain 2 ----
    "posts": [
      {
        "title": "Domain 2 - First post",
        "description": "Content of the first post"
      },
      {
        "title": "Domain 2 - Second post",
        "description": "Content of the second post"
      }
    ]

我知道'stitching'并不意味着像这样的UC,而是将不同的微服务组合到同一个API中。为了在单个API中具有相同的类型(名称),我通过在所有数据类型后附加域名的方式来实现“穷人名称空间”。但是,我只能用两种不同的类型进行查询:

query {
  domain_1_posts {
    title
    description
  }
  domain_2_posts {
    title
    description
  }
}

但是,它的结果是数据集由两个数组组成:

{
  "data": {
    "domain_1_posts": [
      { ...},
    ],
    "domain_2_posts": [
      { ...},
    ]
  }
}

我想听听您的想法,如何将其合并为仅包含posts的单个数据集?一种想法是添加自己的解析器,该解析器可以调用实际的解析器并将结果合并到单个数组中(如果完全支持的话)。另外,作为计划B,我可以忍受发送“域”参数进行查询,然后构造到第一个或第二个域的查询(但是,保持初始查询“域不可知”,例如在查询本身中不使用域命名吗?] >

提前感谢所有建议...

我需要将多个具有相同架构的graphQl服务'聚合'到单个只读(仅查询)服务中,以暴露来自所有服务的数据。例如:----域1 ----“帖子”:[...

express graphql api-design
1个回答
0
投票

我设法找到我用例的解决方案,所以,如果有人碰到这个线程,我将其留在这里...

© www.soinside.com 2019 - 2024. All rights reserved.