NestJS GraphQL 项目教程

NestJS GraphQL 项目教程

nestjs-graphqlnest-js starter which implement graphql module项目地址:https://gitcode.com/gh_mirrors/ne/nestjs-graphql

1. 项目的目录结构及介绍

nestjs-graphql/
├── src/
│   ├── app.module.ts
│   ├── main.ts
│   ├── graphql/
│   │   ├── resolvers/
│   │   │   └── user.resolver.ts
│   │   ├── schemas/
│   │   │   └── user.schema.ts
│   │   └── services/
│   │       └── user.service.ts
│   ├── config/
│   │   └── graphql.config.ts
│   └── ...
├── package.json
├── tsconfig.json
└── ...
  • src/:项目的源代码目录。
    • app.module.ts:应用程序的根模块。
    • main.ts:应用程序的入口文件。
    • graphql/:GraphQL 相关代码。
      • resolvers/:GraphQL 解析器。
      • schemas/:GraphQL 模式定义。
      • services/:业务逻辑服务。
    • config/:配置文件目录。
  • package.json:项目的依赖管理文件。
  • tsconfig.json:TypeScript 配置文件。

2. 项目的启动文件介绍

main.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(3000);
}
bootstrap();
  • NestFactory.create(AppModule):创建 NestJS 应用程序实例。
  • app.listen(3000):启动应用程序并监听 3000 端口。

3. 项目的配置文件介绍

graphql.config.ts

import { GqlModuleOptions, GqlOptionsFactory } from '@nestjs/graphql';
import { Injectable } from '@nestjs/common';

@Injectable()
export class GraphQLConfigService implements GqlOptionsFactory {
  createGqlOptions(): GqlModuleOptions {
    return {
      typePaths: ['./src/graphql/schemas/*.graphql'],
      resolverValidationOptions: {
        requireResolversForResolveType: false,
      },
    };
  }
}
  • typePaths:指定 GraphQL 模式文件的路径。
  • resolverValidationOptions:解析器验证选项。

以上是 NestJS GraphQL 项目的基本教程,涵盖了项目的目录结构、启动文件和配置文件的介绍。希望对你有所帮助!

nestjs-graphqlnest-js starter which implement graphql module项目地址:https://gitcode.com/gh_mirrors/ne/nestjs-graphql

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

侯霆垣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值