标签: apollo-federation

Apollo Federation 子图之间的服务间通信

假设我们有S1S2子图和G网关。

S1子图服务需要来自服务的一些数据S2。应该如何通过网关和模式级别进行处理?在这种通信中我们应该使用网关吗?

我们是否应该在包含内部查询和突变的每个子图中都有一个单独的模式和 Apollo 服务器?应该S1直接调用S2“内部apollo服务器”吗?

默认情况下,所有面向用户的请求都需要经过 JWT 授权,但内部通信无需经过此授权即可正常工作。

子图在公共网络上不可用,但它们在同一内部网络上运行。从技术上讲,他们可以看到对方。它们托管在 GKE 上。

node.js apollo google-kubernetes-engine graphql apollo-federation

9
推荐指数
1
解决办法
1832
查看次数

是否可以有部分联合网关?

我想联合服务,但为了简单起见,让联合网关也拥有自己的模式和逻辑,可以代理 REST API 端点。现在看起来我需要分别拥有联合网关服务、联合 graphql 服务和其余 <->graphql 桥接服务。无论如何,在我们的例子中,rest-graphql 网关至少暂时可以位于联邦网关中,以避免不必要的引导和维护。

看起来阿波罗联邦网关localServiceList似乎正是为了这个目的。一个示例配置:

const gateway = new ApolloGateway({
    serviceList: [
        { name: "some-service", url: "http://localhost:40001/graph" }
    ],
    localServiceList: [
        { name: "rest-bridge", typeDefs }
    ]
});
Run Code Online (Sandbox Code Playgroud)

但它并没有解决问题:如果有 localServiceList,它会跳过 serviceList。

所以问题是:这是否可以在阿波罗联盟网关中保存自己的模式和逻辑?

federation apollo graphql apollo-server apollo-federation

8
推荐指数
1
解决办法
1304
查看次数

@apollo/federation 使用文档中的示例引发错误

在遇到问题后,我自己尝试了一些东西,我尝试了文档中的示例,但遇到了类似的问题,文档是错误的,还是我在做一些愚蠢的事情?

我尝试执行的示例是此页面中的示例:https : //www.apollographql.com/docs/apollo-server/federation/introduction/

相关的一段代码是:

const server = new ApolloServer({
  schema: buildFederatedSchema([{
    typeDefs: gql`
      extend type Query {
        me: User
      }

      type User @key(fields: "id") {
        id: ID!
        username: String!
      }
    `,
    resolvers: [],
  }, {
    typeDefs: gql`
      extend type Query {
        topProducts(first: Int = 5): [Product]
      }

      type Product @key(fields: "upc") {
        upc: String!
        name: String!
        price: Int
      }
    `,
    resolvers: [],
  }, {
    typeDefs: gql`
      type Review {
        body: String
        author: User @provides(fields: "username")
        product: Product
      } …
Run Code Online (Sandbox Code Playgroud)

apollo graphql apollo-server apollo-federation

6
推荐指数
0
解决办法
826
查看次数

自动重新加载网关以适应联合服务 apollo GraphQL 中的架构更改

在 Apollo Federation 中,我面临这样的问题:每次我们对服务列表中的任何联合服务的架构进行更改时,都需要重新启动网关。据我所知,每次网关启动时,它都会收集所有架构并聚合数据图。但是有没有一种方法可以在不重新启动网关的情况下自动处理此问题,因为它也会关闭所有其他不受影响的 GraphQL 联合服务

Apollo GraphQL,@apollo/gateway

graphql apollo-server apollo-federation

6
推荐指数
1
解决办法
4732
查看次数

Nestjs + apollo graphql 联合网关由于“错误请求”而无法内省服务,可复制的 git 存储库可用

在 NX monorepo 中,我正在构建 3 个 Nestjs 应用程序,首先是一个auth-service+user-service和一个。gateway它们均由 apollo graphql 提供支持并遵循官方 Nestjs 文档。

我遇到的问题是,在user-service作为auth-service单独服务器成功处理请求的同时,网关抛出

 Couldn't load service definitions for "auth" at http://localhost:3100/apis/auth-service/graphql: 400: Bad Request
Run Code Online (Sandbox Code Playgroud)

这些服务本身是标准的 graphql 应用程序,没有什么基础的。

网关的定义如下:

{
server: {
          debug: true,
          playground: true,
          autoSchemaFile: './apps/gateway/schema.gql',
          sortSchema: true,
          introspection: true,
          cors: ['*'],
          path: '/apis/gateway/graphql';
        },
gateway: {
            supergraphSdl: new IntrospectAndCompose({
              subgraphHealthCheck: true,
              subgraphs: [
                {
                  name: 'user',
                  url: resolveSubgraphUrl('user'),
                },
                {
                  name: 'auth',
                  url: resolveSubgraphUrl('auth'),
                },
              ],
            }), …
Run Code Online (Sandbox Code Playgroud)

graphql nestjs apollo-federation graphql-federation nestjs-graphql

6
推荐指数
0
解决办法
489
查看次数

如何联合提供相同类型的两个阿波罗服务

我是阿波罗的新手,我有两个阿波罗服务,我想通过使用阿波罗联合来联合:

产品服务:

extend type Query {
  job(id: String!): Job
}

type Seo {
  title: String! 
  description: String! 
  keywords: String! 
}

type Product @key(fields: "id")  {
  id: ID!
  title: String!
  seo: Seo!
}
Run Code Online (Sandbox Code Playgroud)

员工服务:

extend type Query {
  staffMember(id: String!): StaffMember
}

type Seo {
  title: String! 
  description: String! 
  keywords: String! 
}

type StaffMember @key(fields: "id")  {
  id: ID!
  title: String!
  seo: Seo!
}
Run Code Online (Sandbox Code Playgroud)

如何在两个对象的响应对象中使用类型Seo?创建接口 Seo 并实现 StaffMemberSeo 和 ProductSeo 的过程是否正确,或者是否有允许我在两个服务中定义完全相同类型的注释?

apollo graphql apollo-federation

5
推荐指数
1
解决办法
163
查看次数

使用 Apollo Federated GraphQL,有没有办法对来自外部实体的值进行排序/分页?

是否可以将查询输入中的字段标记为需要由不同服务扩展的字段?

使用联邦演示来说明我的问题,但保持更简单一点。只有一个帐户服务和一个评论服务,并向karma用户添加一个字段,是否可以根据用户业力过滤评论。

帐户服务,向用户添加 karma int:

  extend type Query {
    me: User
  }
  type User @key(fields: "id") {
    id: ID!
    name: String
    username: String
    karma: Int!
  }
Run Code Online (Sandbox Code Playgroud)

评论服务,添加评论查询:

  extend type Query {
    reviews(minKarma: Int): [Review!]!
  }
  type Review @key(fields: "id") {
    id: ID!
    body: String
    author: User @provides(fields: "username")
    product: Product
  }
  extend type User @key(fields: "id") {
    id: ID! @external
    username: String @external
    karma: Int! @external
    reviews: [Review]
  }
  extend type Product @key(fields: "upc") {
    upc: …
Run Code Online (Sandbox Code Playgroud)

graphql apollo-federation apollo-gateway

5
推荐指数
1
解决办法
189
查看次数

apollo 网关仅支持 HTTP(S) 协议

我正在尝试使用 apollo 托管解决方案中的托管配置在本地运行 apollo 网关。它加载架构并且一切都很好,但是当我在 Playground 中尝试查询时,我得到“仅支持 HTTP(S) 协议”。我知道我可以使用 serviceList,但我希望能够使用 apollo 图管理器在 POC 本地运行它。这似乎是阿波罗使用的节点获取的问题,因为它甚至没有调用底层数据源并且在网关处失败。

在此输入图像描述

/* istanbul ignore file */
import {ApolloServer} from 'apollo-server';

import {ApolloGateway} from '@apollo/gateway';

 const {
   NODE_ENV,
 } = process.env;


 const gateway: ApolloGateway = new ApolloGateway();

 const main = async () => {
    return new ApolloServer({
        gateway,
        playground: NODE_ENV !== 'production',
        subscriptions: false,
 });
}

export default main;
Run Code Online (Sandbox Code Playgroud)

我在网上到处搜索,似乎找不到答案,所以任何帮助将不胜感激。有什么想法如何让它在本地工作吗?提前致谢。

node.js graphql apollo-server node-fetch apollo-federation

5
推荐指数
1
解决办法
2191
查看次数

微服务架构中的缓存 Nestjs + Apollo 联邦

我正在寻找一种在 Nestjs + graphql 中实现缓存的方法。我已经通过阿波罗联盟分发了我的服务,因此使用微服务架构。

我想要,如果 graphql 查询、标头、参数中的任何内容发生变化,那么它应该获取新数据,否则从缓存中获取数据。

阅读 Nest js 和 graphql 文档,尝试阅读多篇文章,但无法找到如何实现上述内容。

有人可以帮忙吗?

caching microservices graphql nestjs apollo-federation

5
推荐指数
0
解决办法
472
查看次数

Apollo GraphQL 动态认证子图

我正在构建一个带有联合模式的 Apollo 网关 - 并且我有许多子图 - 每个子图都有自己的身份验证令牌(例如许多 REST API,每个用户在每个 REST API 的数据库中保存了自己的令牌)。

我正在为网关中的每个用户的每个 REST API 获取令牌,以减少每个子图的过载并检查网关级别的权限,但我正在努力解决如何将凭据从网关传递到每个子图的问题。

我遇到了这个答案,但是,在这里他正在构建自己serviceList,而我正在使用 Apollo Federation - 并且网关对象无法访问,serviceMap因为它在 Typescript 定义下是私有的 - 这是一种非常黑客的方式实现它的方法:

class RequestHander extends RemoteGraphQLDataSource {
    willSendRequest({ request }: { request: GraphQLRequest }) {
        // if request.http.url matches url of a service which you
        // use, add api-key to headers, e.g.
        if (request.http.url === 'http://localhost:3001') {
            request.http.headers.set('api-key', <API_KEY>)
        }
    }
}

const main = () => {
    const gateway = …
Run Code Online (Sandbox Code Playgroud)

apollo graphql graphql-js apollo-server apollo-federation

5
推荐指数
1
解决办法
924
查看次数

GraphQL-Mesh 和 Apollo-Federation 有什么区别?

GraphQL-Mesh 和 Apollo-Federation 有什么区别?

我看到网格支持联合,这有点混乱?

难道只是通过两种不同的方式来实现统一的模式吗?

为什么您会选择一种解决方案而不是另一种?

apollo-federation graphql-mesh

4
推荐指数
1
解决办法
2980
查看次数

如何在 NestJS 中热重载联合网关

问题

在联合嵌套应用程序中,网关收集来自其他服务的所有架构并形成完整的图。问题是,子模式更改后如何重新运行模式集合?

当前的解决方法

重新启动网关可以解决问题,但这似乎不是一个优雅的解决方案。

其他资源

  1. Apollo 服务器支持托管联合,这本质上恢复了网关和服务之间的依赖关系。遗憾的是我找不到任何与 NestJS 相关的内容。

graphql nestjs apollo-federation

2
推荐指数
1
解决办法
1486
查看次数

Apollo 联合网关和另一个服务器实现

我正在阅读有关阿波罗联邦以及如何从模式拼接迁移的信息,当我阅读时出现了一个问题:

从拼接网关迁移到 Apollo Federation 的基本策略是首先使底层服务具有联邦能力

https://www.apollographql.com/docs/apollo-server/federation/migrating-from-stitching/#adding-federation-support-to-services

基本上联邦网关不能接受另一个不知道联邦的服务?所以没有办法将联合与另一个 graphql 服务器(例如https://github.com/nuwave/lighthouse)一起使用,还是我应该误解那条线?

apollo-server apollo-federation

1
推荐指数
1
解决办法
1878
查看次数