项目作者: notadd

项目描述 :
a simple tool to generate graphql for @nestjs/graphql
高级语言: TypeScript
项目地址: git://github.com/notadd/notadd-cli.git
创建时间: 2019-09-27T03:24:53Z
项目社区:https://github.com/notadd/notadd-cli

开源协议:

下载


English | 简体中文

支持nestjs/nger

功能特点

  • 纯 Typescript 生成,无需维护 graphql 文件
  • 无依赖

TODO

  • 支持同时生成 proto 文件(grpc 用)
  • 支持 webapck 打包发布

@notadd/cli

一个轻量级的生成.graphql文件的工具

安装
  1. npm i -g @notadd/cli
build nodejs project

生产模式

  1. notadd build --prod

开发模式

  1. notadd build --dev
use
  1. notadd graphql
  2. -i main.ts // input file default `main.ts`
  3. -o notadd.graphql // output file default `notadd.graphql`
demo.ts and run notadd graphql
  1. import { Resolver, Query } from "@nestjs/graphql";
  2. export interface List<T> {
  3. data: T[];
  4. currentPage: number;
  5. pageSize: number;
  6. total: number;
  7. }
  8. export interface User {
  9. username: string;
  10. }
  11. export interface Article {
  12. title: string;
  13. }
  14. @Resolver()
  15. export class DemoResolver {
  16. @Query()
  17. getUser(): List<User> {
  18. return {} as any;
  19. }
  20. @Query()
  21. getArticles(): List<Article> {
  22. return {} as any;
  23. }
  24. }
  1. type User {
  2. username: String!
  3. }
  4. type UserList {
  5. data: [User]!
  6. currentPage: Int!
  7. pageSize: Int!
  8. total: Int!
  9. }
  10. type Article {
  11. title: String!
  12. }
  13. type ArticleList {
  14. data: [Article]!
  15. currentPage: Int!
  16. pageSize: Int!
  17. total: Int!
  18. }
  19. type Query {
  20. getUser: UserList!
  21. getArticles: ArticleList!
  22. }