Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sohelamin/graphql-postgres-go
A GraphQL complete example using Golang & PostgreSQL
https://github.com/sohelamin/graphql-postgres-go
golang graphql postgresql
Last synced: 3 months ago
JSON representation
A GraphQL complete example using Golang & PostgreSQL
- Host: GitHub
- URL: https://github.com/sohelamin/graphql-postgres-go
- Owner: sohelamin
- Created: 2018-04-02T17:50:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-02T17:54:49.000Z (over 6 years ago)
- Last Synced: 2024-09-27T20:21:00.415Z (3 months ago)
- Topics: golang, graphql, postgresql
- Language: Go
- Size: 1.95 KB
- Stars: 75
- Watchers: 4
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GraphQL with Golang
> A GraphQL complete example using Golang & PostgreSQL## Installation
Install the dependencies
```
go get github.com/graphql-go/graphql
go get github.com/graphql-go/handler
go get github.com/lib/pq
```Install & create postgres database
```
brew install postgres
createuser graphql --createdb
createdb graphql -U graphql
psql graphql -U graphql
```
Note: Non-Mac users follow official doc to install the `PostgreSQL`Create the tables
```sql
CREATE TABLE IF NOT EXISTS authors
(
id serial PRIMARY KEY,
name varchar(100) NOT NULL,
email varchar(150) NOT NULL,
created_at date
);CREATE TABLE IF NOT EXISTS posts
(
id serial PRIMARY KEY,
title varchar(100) NOT NULL,
content text NOT NULL,
author_id int,
created_at date
);
```## Usage
Query to get the all authors
```
query {
authors {
id
name
created
}
}
```Query to get a specific author
```
query {
author(id: 1) {
id
name
}
}
```Create new author using mutation
```
mutation {
createAuthor(name: "Sohel Amin", email: "[email protected]") {
id
name
}
}
```Update an author using mutation
```
mutation {
updateAuthor(id: 2, name: "Sohel Amin Shah", email: "[email protected]") {
id
name
}
}
```Delete an author using mutation
```
mutation {
deleteAuthor(id: 2) {
id
}
}
```Query to get the posts with its relation author
```
query {
posts {
id
title
content
author {
id
name
}
}
}
```