Giter VIP home page Giter VIP logo

Comments (1)

lianfanghua avatar lianfanghua commented on May 29, 2024 2

刚把代码拉下来跑了下,发现问题和你一样,而且不止这一个问题,后面还有,分享下我怎么解决的,希望对你有帮助。

运行结果

WX20190716-154112

解决过程

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.