• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

topliceanu/graphql-go-example: Example GraphQL API implemented in Go and backed ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

topliceanu/graphql-go-example

开源软件地址(OpenSource Url):

https://github.com/topliceanu/graphql-go-example

开源编程语言(OpenSource Language):

Go 99.4%

开源软件介绍(OpenSource Introduction):

graphql-go-example

Example GraphQL API implemented in Go and backed by Postgresql

How to run it

To run this project you need to:

  • install golang, see this guide
  • install Masterminds/glide which is a package manager for golang projects.
  • install all the dependencies for this project: glide install, glide will store all dependencies in /vendor folder.
  • install postgresql (for ubuntu follow this guide). For this application, I created a postgresql user called vagrant with vagrant as password and the database called graphql, but of course you can change these settings in ./migrate.sh and in ./main.go files.
  • install mattes/migrate which is a tool to create and run migrations against sql databases.
  • run the migrations which will create the database tables and indexes ./migrate.sh up. If you ever want to clean up the the database run ./migrate.sh down then ./migrate.sh up again.

Commands

This application exposes a single endpoints /graphql which accepts both mutations and queries. The following are examples of curl calls to this endpoint:

curl -XPOST http://vm:8080/graphql -d 'mutation {createUser(email:"[email protected]"){id, email}}'
curl -XPOST http://vm:8080/graphql -d 'mutation {createUser(email:"[email protected]"){id, email}}'
curl -XPOST http://vm:8080/graphql -d 'mutation {follow(follower:1, followee:2)}'
curl -XPOST http://vm:8080/graphql -d 'mutation {unfollow(follower:1, followee:2)}'
curl -XPOST http://vm:8080/graphql -d '{user(id:2){followers{id, email}}}'
curl -XPOST http://vm:8080/graphql -d '{user(id:1){followers{id, email}}}'
curl -XPOST http://vm:8080/graphql -d '{user(id:2){follower(id:1){ email}}}'
curl -XPOST http://vm:8080/graphql -d '{user(id:1){followees{email}}}'
curl -XPOST http://vm:8080/graphql -d '{user(id:1){followee(id:2){email}}}'
curl -XPOST http://vm:8080/graphql -d 'mutation {createPost(user:1,title:"p1",body:"b1"){id}}'
curl -XPOST http://vm:8080/graphql -d 'mutation {createComment(user:1,post:1,title:"t1",body:"b1"){id}}'
curl -XPOST http://vm:8080/graphql -d 'mutation {removeComment(id:1)}'
curl -XPOST http://vm:8080/graphql -d 'mutation {removePost(id:1)}'
curl -XPOST http://vm:8080/graphql -d '{user(id:1){post(id:2){title,body}}}'
curl -XPOST http://vm:8080/graphql -d '{user(id:1){posts{id,title,body}}}'
curl -XPOST http://vm:8080/graphql -d '{user(id:1){post(id:2){user{id,email}}}}'



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
GraphQLGuide/guide: 发布时间:2022-06-13
下一篇:
join-monster/join-monster: A GraphQL to SQL query execution layer for query plan ...发布时间:2022-06-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap