小项目的阿波罗联合会

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

我是graphQL,Apollo等的新手。很快,我将致力于一个低成本应用程序,该应用程序具有3个(rest-api)数据源,并且只有1个使用者来创建(主要是)用户类型。计划将无服务器功能用作托管。我一直在阅读模式拼接,联合身份验证和模块,但是找不到为什么我应该在这个小项目中使用Apollo联合身份验证的好答案。据我了解,您需要多个apollo服务器,并且与单块Apollo服务器相比,由于它的原因,它将具有更高的部署/无服务器成本。

一个简化的示例:

服务器1:

  type User {
   id: ID!
    firstname: String
  }

服务器2:

  extend type User @key(fields: "id") {
    lastname: String
  }

服务器3:

  extend type User @key(fields: "id") {
    email: String
  }

您是否建议我仍然使用Apollo联盟或不推荐使用的模式缝合。 graphql-modules可以是一个好的解决方案还是另一个插件?

graphql apollo-server apollo-federation
1个回答
0
投票

如果您只有一个用户架构,那么使用阿波罗联合会不是一个好主意。单个Apollo服务器就足够了。您可以使一台服务器与多个数据源对话。阿波罗联盟(Apollo Federation)基本上是拼接的新版本。 (不建议使用针脚)模式针脚和Apollo联合都适用于微服务。

例如,如果您正在构建一个电子商务后端。您可以让一台服务器处理与用户类型相关的查询和更改(登录,注册,用户信息等)。您将需要其他服务来订购,产品,库存等。

通常,每个服务一个域(架构)。

关于扩展类型,您显示的示例并不理想。姓氏和电子邮件可能应该在用户服务中声明。

您将在以下情况之一中扩展用户类型:

  1. 例如,如果您在另一个架构中引用用户类型,则>]
  2. type Order {
      id:ID!
      products: [Product!]!
      user: User! //the user which did the order
    }
    
    2. If you want to add a field to the User schema.
    For example, you might want to relate all the orders made by a certain user.
    

扩展类型用户@key(fields:“ id”){ID:ID!订单:[订购!]!}

Then in your order service, you can add a resolver that returns all the orders according to user's `id`
© www.soinside.com 2019 - 2024. All rights reserved.