The idea behind this library is to build an alternative way to query databases using GraphQL instead of SQL. Unlike with direct SQL or an ORM you don't have to write all the steps required to get the data you want in the structure you need, instead just describe it with GraphQL and you'll get exactly the data back.
package main
import ( "database/sql" "fmt" "time" "github.com/dosco/super-graph/core" _ "github.com/jackc/pgx/v4/stdlib" )
func main() { db, err := sql.Open("pgx", "postgres://postgrs:@localhost:5432/example_db") if err != nil { log.Fatal(err) }
sg, err := core.NewSuperGraph(nil, db)
if err != nil {
log.Fatal(err)
}
// And here's the GraphQL query to fetch posts, comments, author, etc
query := `
query {
posts {
id
title
body
comments(limit: 5) {
id
user {
id
name
}
}
user {
id
name
}
}
}`
res, err := sg.GraphQL(context.Background(), query, nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(res.Data))
}https://github.com/dosco/super-graph