使用Nestjs角度通用设置时找不到api / graphql

时间:2019-07-09 06:06:26

标签: angular graphql nestjs angular-universal

我在nestjs角度通用设置中找不到GraphQL端点。我使用ng add @ nestjs / ng-universal添加ssr / angularuniversal。 ssr正在其他端点正常工作,但我找不到GraphQL端点

// app.module.ts(nestjs)
import { Module } from '@nestjs/common';
import { AngularUniversalModule } from '@nestjs/ng-universal';
import { join } from 'path';

import { GraphQLModule } from '@nestjs/graphql';

import { HelloModule } from './src/hello/hello.module';
@Module({
  imports: [
    HelloModule,
    GraphQLModule.forRoot({
      autoSchemaFile: './server/schema.gql',
    }),

    AngularUniversalModule.forRoot({
      viewsPath: join(process.cwd(), 'dist/browser'),
      bundle: require('../server/main'),
      liveReload: true,
    }),
  ],
  controllers: [],
})
export class ApplicationModule {}
// hello.module.ts(nestjs)
import { Module } from '@nestjs/common';
import { HelloResolver } from './hello.resolver';
import { HelloController } from './hello.controller';
@Module({
  imports: [],
  controllers: [HelloController],
  providers: [HelloResolver],
})
export class HelloModule {}
// hello.resolver.ts
import { Resolver, Query } from 'type-graphql';

@Resolver()
export class HelloResolver {
  @Query(() => String)
  hello() {
    return 'hello';
  }
}


# schema.gql
# -----------------------------------------------
# !!! THIS FILE WAS GENERATED BY TYPE-GRAPHQL !!!
# !!!   DO NOT MODIFY THIS FILE BY YOURSELF   !!!
# -----------------------------------------------

type Query {
  hello: String!
}

我认为api / graphql应该提供graphql PlayGround服务,但它会重定向到“ /”

1 个答案:

答案 0 :(得分:0)

GraphQLModule实际上没有考虑您设置的任何globalPrefix,因此除非您另外指定,否则它的端点就位于/graphql