Skip to content

Commit

Permalink
fix: Library's NewSuperGraph returns error #165
Browse files Browse the repository at this point in the history
  • Loading branch information
dosco committed Dec 10, 2020
1 parent f95ee36 commit 5730736
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func NewSuperGraph(conf *Config, db *sql.DB) (*SuperGraph, error) {
// newSuperGraph helps with writing tests and benchmarks
func newSuperGraph(conf *Config, db *sql.DB, dbinfo *sdata.DBInfo) (*SuperGraph, error) {
if conf == nil {
conf = &Config{Debug: true}
conf = &Config{Debug: true, DisableAllowList: true}
}

sg := &SuperGraph{
Expand Down
7 changes: 4 additions & 3 deletions core/internal/allow/allow.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,14 @@ func (al *List) Load() ([]Item, error) {
var items []Item
files, err := ioutil.ReadDir(al.queryPath)
if err != nil {
log.Fatal(err)
return nil, fmt.Errorf("allow list: error reading dir: %s", al.queryPath)
}

for _, f := range files {
b, err := ioutil.ReadFile(path.Join(al.queryPath, f.Name()))
fn := path.Join(al.queryPath, f.Name())
b, err := ioutil.ReadFile(fn)
if err != nil {
return nil, err
return nil, fmt.Errorf("allow list: error reading file: %s", fn)
}
item, err := parse(string(b))
if err != nil {
Expand Down
42 changes: 42 additions & 0 deletions libtest/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"context"
"database/sql"
"fmt"

"github.com/dosco/super-graph/core"
_ "github.com/jackc/pgx/v4/stdlib"
)

// run `docker-compose up` in the repository root before
// running this test script with `go run *.go`
func main() {
db, err := sql.Open("pgx", "postgres://postgres:postgres@localhost:5432/webshop_development")
if err != nil {
panic(err)
}

sg, err := core.NewSuperGraph(nil, db)
if err != nil {
panic(err)
}

query := `
query {
products {
id
name
}
}`

ctx := context.Background()
ctx = context.WithValue(ctx, core.UserIDKey, 1)

res, err := sg.GraphQL(ctx, query, nil)
if err != nil {
panic(err)
}

fmt.Println(string(res.Data))
}

0 comments on commit 5730736

Please sign in to comment.