我正在尝试将nestjs与pyramida集成。我遵循了nestjs文档中的tutorial。
一切正常,直到我想进行一些更改,以便nestjs不会公开所有查询/变异模式。
我所做的是 1.更新应用模块,不要让typePath包含生成的模式
import { Module } from '@nestjs/common';
import { AppController } from 'app/app.controller';
import { AppService } from 'app/app.service';
import { GraphQLModule } from '@nestjs/graphql';
import { UserModule } from './user/user.module';
@Module({
imports: [
GraphQLModule.forRoot({
typePaths: ['./src/**/*.schema.graphql'],
debug: true,
playground: true,
}),
UserModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
2。然后,我在user.schema.graphql
文件夹中创建了一个user
文件:
#import User from "../prisma/generated/prisma.graphql"
type Query {
user(id: ID!): User
}
但是,我出现一些错误,提示我无法导入用户:
(node:36277) UnhandledPromiseRejectionWarning: Error: Type "User" not found in document.
at ASTDefinitionBuilder._resolveType (/Users/anx/Projects/axesk/gallery-api/node_modules/graphql/utilities/buildASTSchema.js:100:11)
at ASTDefinitionBuilder.buildType (/Users/anx/Projects/axesk/gallery-api/node_modules/graphql/utilities/buildASTSchema.js:210:79)
at ASTDefinitionBuilder._buildWrappedType (/Users/anx/Projects/axesk/gallery-api/node_modules/graphql/utilities/buildASTSchema.js:229:17)
at ASTDefinitionBuilder.buildField (/Users/anx/Projects/axesk/gallery-api/node_modules/graphql/utilities/buildASTSchema.js:249:18)
at /Users/anx/Projects/axesk/gallery-api/node_modules/graphql/utilities/buildASTSchema.js:332:21
at /Users/anx/Projects/axesk/gallery-api/node_modules/graphql/jsutils/keyValMap.js:36:31
at Array.reduce (<anonymous>)
at keyValMap (/Users/anx/Projects/axesk/gallery-api/node_modules/graphql/jsutils/keyValMap.js:35:15)
at ASTDefinitionBuilder._makeFieldDefMap (/Users/anx/Projects/axesk/gallery-api/node_modules/graphql/utilities/buildASTSchema.js:329:48)
at fields (/Users/anx/Projects/axesk/gallery-api/node_modules/graphql/utilities/buildASTSchema.js:312:22)
(node:36277) 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: 2)
(node:36277) [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.
我是NestJS和graphql的新手,请帮忙!
答案 0 :(得分:1)
我使它以某种黑客方式工作。.我将在这里粘贴我的解决方案给任何遇到相同问题的人。
例如,我有一个using (var conn = new Services.DBConn())
{
var configuration = new Configuration();
configuration.RunSeed(conn);
}
从user.schema.graphql
导入某种类型:
prisma.graphql
然后,我创建一个#import User from "../prisma/generated/prisma.graphql"
type Query {
user(id: ID!): User
}
文件,它将从项目中手动导入每个模式。
main.schema.graphql
最后,只需将此maim模式导入到#import * from "./user/user.schema.graphql"
:
app.module.ts
这样做不是很理想。如果graphql-import库可以从文件夹导入,那么将使工作更轻松。
或@ nest / graphql库可以在内部使用graphql-import而不是merge-graphql-schemas来构建typeDefs。