GraphQL apollo-server 迎来史上最大更新
发布于 10 天前 作者 cheunghy 506 次浏览 最后一次编辑是 9 天前 来自 分享

近期,GraphQL服务器apollo-server迎来2.0版本更新,集成了graphql-tools,自带Upload上传功能,自带服务器,不再依赖express,koa这种服务器软件。 这使得graphql项目结构大大简化,不必要的依赖项全部被省去。 如今,搭建一个纯GraphQL项目,从未如此简单。

GraphQL脚手架工具Amur也跟着做了更新,更新后项目结构更为简洁。

创建一个可以工作的GraphQL API服务器,只需几条命令。

比如写一个博客,命令如下:

npm install -g amur
mkdir gql-example
cd gql-example
amur app .
amur resource User name:String age:Int 'gender:Enum{male,female}' posts:[Post]:user
amur resource Post title:String content:String user:User comments:[Comment]:post commenters:[User]:Comment.commenter.post
amur resource Comment content:String post:Post commenter:User parentComment:Comment childrenComments:[Comment]:parentComment

几行命令,一个带有用户,文章,评论的系统就做好啦~

现在,npm start一下,然后浏览器打开http://localhost:4000,体验graphql API吧。

回到顶部