首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nestjs - @nestjs/graphql GraphQLGatewayModule总是返回错误的请求

Nestjs - @nestjs/graphql GraphQLGatewayModule总是返回错误的请求
EN

Stack Overflow用户
提问于 2020-03-20 23:47:53
回答 1查看 802关注 0票数 0

我正在尝试使用@nestjs/graphql中的GraphQLGatewayModule模块。

为了进行测试,我使用了一个免费的GraphQL应用程序接口:https://anilist.co/graphiql

但我总是得到HTTP400状态。

我的代码:

代码语言:javascript
复制
import { Module } from '@nestjs/common';
import { GraphQLGatewayModule } from '@nestjs/graphql';

@Module({
  imports: [
    GraphQLGatewayModule.forRoot({
      server: {
        // ... Apollo server options
        debug: true,
        cors: true
      },
      gateway: {
        debug: true,
        serviceList: [{ name: 'TEST_GRAPHQL_GATEWAY', url: 'http://user-service:3000/graphql' }],
      }
    })
  ]
})
export class AppModule { }

我总是得到HTTP 400状态。但是这个api是可以的。我得到了这样的信息:

代码语言:javascript
复制
Encountered error when loading TEST_GRAPHQL_GATEWAY at http://user-service:3000/graphql: 400: Bad Request
[INFO] Fri Mar 20 2020 17:52:20 GMT+0000 (Coordinated Universal Time) apollo-gateway: Gateway successfully loaded schema.
    * Mode: unmanaged
(node:368) UnhandledPromiseRejectionWarning: Error: Expected undefined to be a GraphQL schema.
    at assertSchema (/app/node_modules/graphql/type/schema.js:41:11)
    at validateSchema (/app/node_modules/graphql/type/validate.js:44:28)
    at assertValidSchema (/app/node_modules/graphql/type/validate.js:68:16)
    at assertValidExecutionArguments (/app/node_modules/graphql/execution/execute.js:136:35)
    at executeImpl (/app/node_modules/graphql/execution/execute.js:86:3)
    at Object.execute (/app/node_modules/graphql/execution/execute.js:64:63)
    at Object.generateSchemaHash (/app/node_modules/apollo-server-core/dist/utils/schemaHash.js:14:32)
    at ApolloServer.generateSchemaDerivedData (/app/node_modules/apollo-server-core/dist/ApolloServer.js:282:41)
    at ApolloServerBase.schemaDerivedData._schema.then.schema (/app/node_modules/apollo-server-core/dist/ApolloServer.js:206:66)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:368) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:368) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我是否以错误的方式使用GraphQLGatewayModule?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2020-03-21 04:00:09

解决了!

我使用的是一个没有GraphQLFederationModule模块的旧版本的@nestjs/graphql。我尝试将USER api与GraphQLModule模块一起使用

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60777382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档