Comments (1)
刚把代码拉下来跑了下,发现问题和你一样,而且不止这一个问题,后面还有,分享下我怎么解决的,希望对你有帮助。
运行结果
解决过程
errors.interceptor.ts
export class ErrorsInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, calls$: CallHandler<any>): Observable<any> { // calls$的类型改为 CallHandler<any>
return calls$.handle().pipe(catchError((error, caught) => { // pipe前增加.handle()调用
if (error instanceof HttpException) {
return Promise.resolve({
code: error.getStatus(),
message: error.getResponse()
});
}
if (error.code && error.details) {
return Promise.resolve({
code: error.code,
message: error.details
});
}
}));
}
}
graphql-config.service.ts
createGqlOptions(): GqlModuleOptions {
return {
typePaths: ['./**/*.types.graphql'],
resolvers: { JSON: GraphQLJSON }, // 改为resolvers: { JSON: GraphQLJSON.GraphQLJSONObject },
context: async ({ req }) => {
const user = await this.authService.validateUser(req);
return { req, user };
}
};
}
user.module.ts
private scanResourcesAndPermissions() {
const metadataMap: Map<string, { name: string, resource: Resource[] }> = new Map();
this.modulesContainer.forEach((moduleValue, moduleKey) => {
for (const [componentKey, componentKeyValue] of [...moduleValue.components, ...moduleValue.routes]) {
// const isResolverOrController =
// Reflect.getMetadataKeys(componentKeyValue.instance.constructor)
// .filter(key => ['graphql:resolver_type', 'path']
// .includes(key)).length > 0;
// 增加null判断
const isResolverOrController = componentKeyValue.instance ?
Reflect.getMetadataKeys(componentKeyValue.instance.constructor)
.filter(key => ['graphql:resolver_type', 'path']
.includes(key)).length > 0 : undefined;
if (isResolverOrController) {
const resource: Resource = Reflect.getMetadata(RESOURCE_DEFINITION, componentKeyValue.instance.constructor);
const prototype = Object.getPrototypeOf(componentKeyValue.instance);
if (resource && prototype) {
const permissions: Permission[] = this.metadataScanner.scanFromPrototype(componentKeyValue.instance, prototype, name => {
return Reflect.getMetadata(PERMISSION_DEFINITION, componentKeyValue.instance, name);
});
resource.permissions = permissions;
if (metadataMap.has(moduleKey)) {
metadataMap.get(moduleKey).name = t(moduleValue.metatype.name);
metadataMap.get(moduleKey).resource.push(resource);
} else {
metadataMap.set(moduleKey, { name: t(moduleValue.metatype.name), resource: [resource] });
}
}
}
}
});
return metadataMap;
这样notadd项目就正常能运行了。
细节:
- 当然,还要依照README.md克隆nt-rpc-demo和nt-module-user;
- nt-rpc-demo没啥配置的,直接clone,然后npm i就完了,然后npm run start;
- nt-module-user需要安装postgres,然后修改
user.module.ts
里面的typeorm配置,然后npm i,npm run start时会自动同步数据结构到pg中; - 先启动nt-rpc-demo和nt-module-user,再启动notadd就可以了,启动notadd时会通过nt-module-user插入许多初始化数据,可以深入研究。。。
from notadd.
Related Issues (20)
- 跑不起来? HOT 2
- 运行失败!
- Notadd 单元测试
- 快速开始启动notadd报错 HOT 4
- 为什么 windows 10 不能安装? HOT 1
- nest HOT 6
- 这个适合vue一起使用吗 HOT 1
- UnhandledPromiseRejectionWarning HOT 1
- grpc连接报错 HOT 1
- Action Required: Fix Renovate Configuration
- Dependency Dashboard
- Find时条件不起作用
- magnus insert时报错: {"message": "Cannot read property '***' of undefined"}
- 没看到任何价值,如果有,请在readme里面写清楚 HOT 1
- errors.interceptor.ts error HOT 4
- 骗完star就没下文了....
- 骗完star就没下文了... HOT 1
- 希望继续维护此项目 HOT 4
- 你好,这个库还再迭代维护吗 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from notadd.