简体   繁体   English

NestJS 5 GraphQL错误查询在解析器中定义,但不在架构中定义

[英]NestJS 5 GraphQL Error Query defined in resolvers, but not in schema

I'm getting an error similar to the error described in Query.products is defined in resolvers but not in schema but only when I push to Heroku. 我收到的错误类似于Query.products中描述的错误在解析器中定义但在架构中没有定义,但仅在我推送到Heroku时。 Here are the details: 以下是详细信息:

// profile.graphql
type Profile {
  id: ID!
  version: String!
  // ...
}

type Query {
  profile(id: ID!): Profile
  profiles: [Profile]
}
// profiles.resolver.ts
import { Args, Query, Resolver } from '@nestjs/graphql'
import { Profile } from './profile.entity'

@Resolver('Profile')
export class ProfileResolver {
  @Query()
  public async profile(@Args('id') id: number) {
    return await Profile.findOne(id)
  }

  @Query()
  public async profiles() {
    return await Profile.find()
  }
}

Locally, I can run yarn start:dev and it works great. 在本地,我可以运行yarn start:dev并且效果很好。 The application starts successfully and I can query my GraphQL endpoint without a problem. 应用程序启动成功,我可以毫无问题地查询我的GraphQL端点。

When I push this to Heroku, the application never starts up. 当我将其推送到Heroku时,应用程序永远不会启动。

2019-04-03T15:42:38.102056+00:00 heroku[web.1]: Starting process with command `node dist/main.js`
2019-04-03T15:42:42.448420+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [NestFactory] Starting Nest application...
2019-04-03T15:42:42.499150+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] ConfigModule dependencies initialized +51ms
2019-04-03T15:42:42.499439+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] TypeormConfigModule dependencies initialized +0ms
2019-04-03T15:42:42.499805+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] TypeOrmModule dependencies initialized +0ms
2019-04-03T15:42:42.500251+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] ApiModule dependencies initialized +1ms
2019-04-03T15:42:42.500726+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] PassportModule dependencies initialized +0ms
2019-04-03T15:42:42.501201+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] DataModule dependencies initialized +1ms
2019-04-03T15:42:42.501651+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] GqlConfigModule dependencies initialized +0ms
2019-04-03T15:42:42.502039+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] EntitiesModule dependencies initialized +0ms
2019-04-03T15:42:42.502411+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] UsersModule dependencies initialized +0ms
2019-04-03T15:42:42.502819+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] HelpersModule dependencies initialized +0ms
2019-04-03T15:42:42.503246+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] ProfilesModule dependencies initialized +1ms
2019-04-03T15:42:42.503676+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] ResourceTypesModule dependencies initialized +0ms
2019-04-03T15:42:42.504107+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] SchemaMappingsModule dependencies initialized +1ms
2019-04-03T15:42:42.504580+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] SearchReplaceValuesModule dependencies initialized +0ms
2019-04-03T15:42:42.505006+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] XpathExpressionsModule dependencies initialized +0ms
2019-04-03T15:42:42.505581+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] JwtModule dependencies initialized +1ms
2019-04-03T15:42:42.550301+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] AppModule dependencies initialized +45ms
2019-04-03T15:42:42.553207+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] GraphQLModule dependencies initialized +3ms
2019-04-03T15:42:42.553861+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] AuthModule dependencies initialized +0ms
2019-04-03T15:42:42.674522+00:00 app[web.1]: query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = current_schema() AND "table_name" = 'migrations'
2019-04-03T15:42:42.690182+00:00 app[web.1]: query: SELECT * FROM "migrations" "migrations"
2019-04-03T15:42:42.693584+00:00 app[web.1]: No migrations are pending
2019-04-03T15:42:42.696083+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [InstanceLoader] TypeOrmCoreModule dependencies initialized +142ms
2019-04-03T15:42:42.734620+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [RoutesResolver] AppController {/}: +35ms
2019-04-03T15:42:42.735243+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [RouterExplorer] Mapped {/, GET} route +4ms
2019-04-03T15:42:42.735665+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [RoutesResolver] AuthController {/auth}: +0ms
2019-04-03T15:42:42.737212+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [RouterExplorer] Mapped {/register, POST} route +2ms
2019-04-03T15:42:42.739125+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [RouterExplorer] Mapped {/login, POST} route +0ms
2019-04-03T15:42:42.739137+00:00 app[web.1]: [Nest] 4   - 4/3/2019, 3:42:42 PM   [RouterExplorer] Mapped {/refresh, POST} route +0ms
2019-04-03T15:42:42.849522+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: Error: Query.profile defined in resolvers, but not in schema

Why do I get the error in production and not in development? 为什么我在生产中而不是在开发中遇到错误? What is happening that makes the GraphQL schema not register my profile query? 是什么让GraphQL架构没有注册我的profile查询?

The difference between local and prod lends itself to Typescript. local和prod之间的区别适用于Typescript。 I found out that none of the .graphql files were being copied by Typescript so I used copyfiles to solve the issue after my dist folder was created. 我发现没有任何.graphql文件被.graphql复制,因此我在创建dist文件夹后使用了copyfiles来解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 NestJS + GraphQL 中实现“命名空间类型”解析器 - Implementing 'Namespace-Typed' Resolvers in NestJS + GraphQL NestJS - 预期未定义为 GraphQL 架构 - NestJS - Expected undefined to be a GraphQL schema 使用@nestjs/graphql 使用@ResolveProperty 和@Resolvers 创建嵌套查询 - Using @nestjs/graphql to create nested queries using @ResolveProperty and @Resolvers Apollo GraphQL Schema使用Typescript时解析器的拼接问题 - Apollo GraphQL Schema Stitching issue with Resolvers when using Typescript NestJS中的测试解析器 - Test resolvers in NestJS 将 GraphQL 解析器连接到数据库 - Connect GraphQL resolvers to database Nestjs定义GraphQL对象类型得到这个错误:架构必须包含唯一命名的类型但包含多个名为“地址”的类型 - Nestjs define GraphQL Object type got this error: Schema must contain uniquely named types but contains multiple types named "Address" 我们如何通过apollo-server模块在ApolloServer中传递数据源以及合并的graphql模式和解析器? - How can we pass datasource and merged graphql schema and resolvers in ApolloServer from apollo-server module? 使用Schema First方法和NestJS在Mongoose中填充查询 - Populate a query in Mongoose with Schema First approach and NestJS 在 GraphQL Resolvers 文件中定义一个函数 - define a function in the GraphQL Resolvers file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM