0

我目前正在开发一个 POC,以在 NodeJS + express 应用程序中实现 Apollo Federation 网关。到目前为止,我还没有真正遇到任何关于如何正确执行此操作的示例。到目前为止,我遇到了 ApolloServer 模块无法识别ApolloGatewayfrom实例的问题@apollo/gateway。我使用 ApolloServer 实例作为网关实例的包装器,如教程所示:https ://www.apollographql.com/docs/apollo-server/federation/implementing/#defining-the-gateway 。server.applyMiddleWare()但是,在我的快递应用程序中调用时遇到了问题。我从https://github.com/apollographql/apollo-server/tree/master/packages/apollo-server-express#express遇到了这个例子

具体来说,这里是错误日志的片段:

$ node --use_strict ./bin/www
/Users/evanlee/dev/federation-gateway/node_modules/loglevel-debug/index.js:32
    target[k] = attr.bind ? attr.bind(k) : attr;
              ^

TypeError: Cannot assign to read only property 'name' of function 'function() {
    return log.debug.apply(this, arguments);
  }'
    at /Users/evanlee/dev/federation-gateway/node_modules/loglevel-debug/index.js:32:15
    at Array.forEach (<anonymous>)
    at composit (/Users/evanlee/dev/federation-gateway/node_modules/loglevel-debug/index.js:30:20)
    at Object.loglevelDebug [as default] (/Users/evanlee/dev/federation-gateway/node_modules/loglevel-debug/index.js:201:3)
    at new ApolloGateway (/Users/evanlee/dev/federation-gateway/node_modules/@apollo/gateway/dist/index.js:101:33)
    at Object.<anonymous> (/Users/evanlee/dev/federation-gateway/app.js:21:12)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
error Command failed with exit code 1.

以下是我尝试将 ApolloServer 集成到我的 express 应用程序的方式:

const { ApolloServer } = require('apollo-server');
const { ApolloGateway } = require('@apollo/gateway');

const app = express();

// Apollo Server and Gateway definition
const server = new ApolloServer({
  gateway: new ApolloGateway({
    debug: true,
    serviceList: [
      { name: 'base-app', url: 'http://localhost:4001/graphql' },
    ]
  }),
  subscriptions: false,
});

server.applyMiddleware({ app, path: '/graphql' });

非常感谢您的帮助!

4

1 回答 1

0

它使用最新的对我有用。但是,我没有使用debug: truetry without?

于 2020-03-31T13:54:29.563 回答