Api TypeGraphQL类式Schema框架

TypeScript 的 GraphQL 服务,推荐你试试这个 Api-typegql.zip,用类来写 schema,挺优雅的。比起写一堆繁琐的 SDL,这种方式代码结构更清晰,类型检查也一步到位,尤其适合用在中大型项目里。

基于TypeGraphQL的写法,类就是类型,装饰器直接映射字段,不需要再转来转去,像定义接口一样顺手。举个例子:

import { ObjectType, Field } from 'type-graphql';

@ObjectType() class User { @Field() id: number;

@Field() name: string; }

是不是比写 SDL 清爽多了?字段类型、可空性都一目了然,还能跟着 TypeScript 自动补全,写起来贼快。

哦对了,这种结构适合配合 TypeORM 或 Prisma,用类一套到底,前后端 schema 同步也不再头大。

想搭建一个从零开始的项目,可以参考这篇GraphQL TypeScript Starter 安装和数据库配置,数据库那块讲得挺细。

另外,TypeGraphQL 构建 GraphQL 服务器教程 也不错,适合边看边动手,理解更快。

如果你用的是 React + Apollo,可以顺手看看这个 graphql-react-typescript 示例,接上前端也方便。

Api-typegql.zip挺适合快速搭一个结构清晰的 GraphQL 服务。如果你用惯了 TypeScript,又想 schema 写得不那么啰嗦,可以下载试试看。

zip
Api-typegql.zip 预估大小:177个文件
file
.travis.yml 127B
file
rollup.config.js 332B
file
index.md 3KB
folder
minimal-demo.md 文件夹
file
setup.md 747B
file
what-is-typegql.md 612B
file
README.md 4KB
file
SUMMARY.md 1KB
file
before-and-after.md 1KB
file
index.md 374B
file
authorization-example.md 2KB
file
object-type-and-field.md 2KB
folder
query-and-mutation.md 文件夹
folder
compile-schema.md 文件夹
file
index.md 4KB
file
arg.md 1KB
file
union.md 664B
file
input-type-and-input-field.md 984B
folder
register-enum.md 文件夹
file
index.md 963B
folder
context-source-info.md 文件夹
file
index.md 1KB
file
package.json 1KB
file
.prettierrc 52B
file
demo.gif 1.67MB
file
book.json 45B
file
jest.config.js 382B
file
LICENSE 1KB
file
ttsconfig.json 292B
file
registry.ts 1KB
file
index.ts 644B
file
error.ts 280B
file
fieldType.ts 2KB
file
services.ts 1KB
file
index.ts 2KB
file
resolver.ts 3KB
file
registry.ts 560B
file
index.ts 745B
file
error.ts 282B
file
compiler.ts 2KB
file
registry.ts 123B
file
index.ts 518B
file
error.ts 247B
file
compiler.ts 2KB
file
services.ts 1KB
file
rootFields.ts 2KB
file
registry.ts 577B
file
index.ts 804B
file
error.ts 682B
file
compiler.ts 4KB
file
options.ts 166B
file
registry.ts 341B
file
index.ts 455B
file
error.ts 518B
file
objectType.ts 2KB
file
index.ts 79B
file
registry.ts 378B
file
index.ts 661B
file
error.ts 257B
file
fieldType.ts 1KB
file
index.ts 2KB
file
registry.ts 427B
file
index.ts 757B
file
error.ts 287B
file
services.ts 410B
file
registry.ts 113B
file
index.ts 832B
file
error.ts 231B
file
objectType.ts 2KB
file
index.ts 94B
file
registry.ts 285B
file
index.ts 695B
file
error.ts 267B
file
index.ts 617B
file
registry.ts 556B
file
index.ts 609B
file
index.spec.ts 402B
file
index.spec.ts.snap 142B
file
index.spec.ts 3KB
file
enum.spec.ts 895B
file
mutation.spec.ts 1KB
file
query.spec.ts 1KB
file
query.spec.ts.snap 169B
file
enum.spec.ts.snap 209B
file
fieldArguments.spec.ts.snap 192B
file
mutation.spec.ts.snap 172B
file
inputOutput.spec.ts 683B
file
fieldArguments.spec.ts 955B
file
getters.spec.ts 1KB
file
special-fields.spec.ts 431B
file
index.spec.ts.snap 1KB
file
special-fields.spec.ts.snap 284B
file
index.spec.ts 7KB
file
index.spec.ts 2KB
file
index.spec.ts.snap 33KB
file
index.spec.ts 5KB
file
basics.spec.ts 3KB
file
infering.spec.ts 1KB
file
complex.spec.ts 2KB
file
complex.spec.ts.snap 609B
file
infering.spec.ts.snap 316B
file
index.spec.ts.snap 490B
file
index.spec.ts 2KB
file
inheritance.spec.ts 2KB
file
index.spec.ts.snap 151B
file
index.spec.ts 1KB
file
index.spec.ts.snap 490B
file
index.spec.ts 2KB
file
inheritance.spec.ts 950B
file
index.ts 99B
file
index.spec.ts.snap 239B
file
index.spec.ts 3KB
file
setup.ts 27B
file
index.ts 99B
file
getParameterNames.ts 438B
file
index.ts 398B
file
index.ts 1KB
file
parseNative.ts 903B
file
resolve.ts 2KB
file
index.ts 136B
file
validators.ts 189B
file
index.ts 157B
file
index.ts 421B
file
index.ts 398B
file
cachedThunk.ts 311B
file
error.ts 49B
file
index.ts 377B
file
.npmignore 12B
file
tsconfig.json 616B
file
preprocessor.js 279B
file
package.json 361B
file
tsconfig.json 171B
file
README.md 2KB
file
yarn.lock 38KB
file
index.ts 2KB
file
package.json 315B
file
schema.ts 886B
file
tsconfig.json 171B
file
README.md 388B
file
yarn.lock 14KB
file
index.ts 351B
file
package.json 435B
file
tsconfig.json 171B
file
serverless.yml 495B
file
.gitignore 6B
file
handler.ts 656B
file
README.md 1KB
file
yarn.lock 79KB
file
package.json 315B
file
schema.ts 211B
file
tsconfig.json 171B
file
README.md 797B
file
yarn.lock 14KB
file
index.ts 351B
file
package.json 347B
file
tsconfig.json 171B
file
schemaA.ts 206B
file
README.md 130B
file
yarn.lock 16KB
file
index.ts 554B
file
schemaB.ts 210B
file
package.json 315B
file
schema.ts 897B
file
tsconfig.json 171B
file
README.md 1KB
file
yarn.lock 14KB
file
index.ts 351B
file
package.json 358B
file
tsconfig.json 171B
file
README.md 477B
file
yarn.lock 15KB
file
index.ts 2KB
file
.gitignore 101B
file
CODE_OF_CONDUCT.md 3KB
file
README.md 5KB
file
publish-docs.js 102B
file
yarn.lock 314KB
...
zip 文件大小:1.84MB