0

I am trying to learn Apollo Federation, so I started by looking at their sample (https://github.com/apollographql/federation-demo). This sample repository works great, and I can add a new service as a subgraph in Node.js.

I want to add a new service as a subgraph in .NET Core as well to extend the User type defined in the sample project. I did so by created a new service using graphql-dotnet.

My schema is defined as the following:

extend type User @key(fields: "id") {
    id: ID! @external
    phone: String
}

The GraphQL Playground seems to work properly, but when I try to include the service in my gateway, I get the following error: UnhandledPromiseRejectionWarning: Error: Couldn't load service definitions for "user-service" at http://localhost:5000/graphql: Syntax Error: Expected Name, found "}".

4

1 回答 1

0

显然,这是由于如果您不扩展查询类型,graphql-dotnet 服务器 NuGet 包(当前为 5.0.2)不会生成正确的 SDL。该服务正常启动,我可以导航到 UI Playground。

询问:

query {
  _service {
    sdl
  }
}

结果(json):

{
  "data": {
    "_service": {
      "sdl": "type Query {\r\n\r\n}\r\n\r\nextend type User @key(fields: \"id\") {\r\n  id: ID! @external\r\n  phone: String\r\n}\r\n"
    }
  },
  "extensions": {}
}

请注意,graphql-dotnettype Query {\r\n\r\n}在 SDL 中生成一个空部分,它不应该存在,因为我没有在我的模式中扩展查询类型。我已经打开了graphql-dotnet github 项目的问题。

解决方法可能是使用新功能扩展查询类型,至少在问题得到解决之前。

于 2021-06-02T11:26:36.973 回答