• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 8 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example GraphQL API implemented in Go and backed by Postgresql

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}}}}'

More Repositories

1

mongoose-gen

DEPRECATED!!! generates mongoose schemas from json documents, supports DBRefs and Arrays of DBRef
JavaScript
118
star
2

sum

js utility for summarizing large bodies of text using a basic sentence relevance ranking algorithm
JavaScript
100
star
3

learn

Learn CS by doing!
JavaScript
24
star
4

mortimer

extendible HTTP REST interface for mongoose models
JavaScript
22
star
5

schedule-drone

A reliable, fault-tolerant, persistent event scheduler for node.js
CoffeeScript
5
star
6

alexandrutopliceanu.ro

blog on software development
CSS
4
star
7

xpath

small utility function that calculates a DOMElement's xpath
JavaScript
4
star
8

jAccess

object accessor utility that works like the `?.` operator from coffeescript
JavaScript
2
star
9

backbone.class.js

Utility lib that provides a base class for inheritance with a Backbone consistent syntax
JavaScript
2
star
10

backbone.docs

Backbonejs documentation packaged in a mobile webapp
JavaScript
2
star
11

arrayListener

a small utility that listens to an array reference and triggers events when changes occur
JavaScript
1
star
12

stand

Azure Table Storage Document Object Mapper
CoffeeScript
1
star
13

easter

Amqp/Http pub/sub client for RabbitMQ
CoffeeScript
1
star
14

simplebase

simple backend for your javascript applications
JavaScript
1
star
15

my-gists

collections of reusable components that have lived into gists until now
1
star
16

connect-b2g

Connect middleware that delivers an application manifest compatible with Mozilla's Open Web Apps initiative
JavaScript
1
star
17

boot2twitter

Example app for Mozilla Boot to Gecko Hackfest, uses coffeescript, requirejs, jquery, underscore, backbone and lesscss
JavaScript
1
star
18

phoner

Mobile application emulator, usefull for testing the backend api by emulating the front-end's workflows and communication message signatures
JavaScript
1
star