Compare commits

...

4 Commits

24 changed files with 263 additions and 242 deletions

View File

@ -45,7 +45,7 @@ changelog: $(GITCHGLOG)
@git-chglog $(ARGS) @git-chglog $(ARGS)
$(GOLANGCILINT): $(GOLANGCILINT):
@GO111MODULE=off curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.21.0 @GO111MODULE=off curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.25.1
lint: $(GOLANGCILINT) lint: $(GOLANGCILINT)
@golangci-lint run ./... --skip-dirs-use-default @golangci-lint run ./... --skip-dirs-use-default

View File

@ -45,6 +45,13 @@ cors_allowed_origins: ["*"]
# Debug Cross Origin Resource Sharing requests # Debug Cross Origin Resource Sharing requests
cors_debug: true cors_debug: true
# Default API path prefix is /api you can change it if you like
# api_path: "/data"
# Cache-Control header can help cache queries if your CDN supports cache-control
# on POST requests (does not work with not mutations)
# cache_control: "public, max-age=300, s-maxage=600"
# Postgres related environment Variables # Postgres related environment Variables
# SG_DATABASE_HOST # SG_DATABASE_HOST
# SG_DATABASE_PORT # SG_DATABASE_PORT

View File

@ -174,7 +174,7 @@ func (sg *SuperGraph) GraphQL(c context.Context, query string, vars json.RawMess
// use the chirino/graphql library for introspection queries // use the chirino/graphql library for introspection queries
// disabled when allow list is enforced // disabled when allow list is enforced
if !sg.conf.UseAllowList && res.name == "IntrospectionQuery" { if !sg.conf.UseAllowList && res.name == "IntrospectionQuery" {
r := sg.ge.ExecuteOne(&graphql.EngineRequest{Query: query}) r := sg.ge.ServeGraphQL(&graphql.Request{Query: query})
res.Data = r.Data res.Data = r.Data
if r.Error() != nil { if r.Error() != nil {

View File

@ -9,6 +9,8 @@ import (
"github.com/dosco/super-graph/jsn" "github.com/dosco/super-graph/jsn"
) )
// argMap function is used to string replace variables with values by
// the fasttemplate code
func (c *scontext) argMap() func(w io.Writer, tag string) (int, error) { func (c *scontext) argMap() func(w io.Writer, tag string) (int, error) {
return func(w io.Writer, tag string) (int, error) { return func(w io.Writer, tag string) (int, error) {
switch tag { switch tag {
@ -56,10 +58,13 @@ func (c *scontext) argMap() func(w io.Writer, tag string) (int, error) {
return w.Write(v1) return w.Write(v1)
} }
return w.Write(escQuote(fields[0].Value)) return w.Write(escSQuote(fields[0].Value))
} }
} }
// argList function is used to create a list of arguments to pass
// to a prepared statement. FYI no escaping of single quotes is
// needed here
func (c *scontext) argList(args [][]byte) ([]interface{}, error) { func (c *scontext) argList(args [][]byte) ([]interface{}, error) {
vars := make([]interface{}, len(args)) vars := make([]interface{}, len(args))
@ -113,7 +118,7 @@ func (c *scontext) argList(args [][]byte) ([]interface{}, error) {
if v, ok := fields[string(av)]; ok { if v, ok := fields[string(av)]; ok {
switch v[0] { switch v[0] {
case '[', '{': case '[', '{':
vars[i] = escQuote(v) vars[i] = v
default: default:
var val interface{} var val interface{}
if err := json.Unmarshal(v, &val); err != nil { if err := json.Unmarshal(v, &val); err != nil {
@ -132,27 +137,25 @@ func (c *scontext) argList(args [][]byte) ([]interface{}, error) {
return vars, nil return vars, nil
} }
func escQuote(b []byte) []byte { //
f := false func escSQuote(b []byte) []byte {
for i := range b { var buf *bytes.Buffer
if b[i] == '\'' {
f = true
break
}
}
if !f {
return b
}
buf := &bytes.Buffer{}
s := 0 s := 0
for i := range b { for i := range b {
if b[i] == '\'' { if b[i] == '\'' {
if buf == nil {
buf = &bytes.Buffer{}
}
buf.Write(b[s:i]) buf.Write(b[s:i])
buf.WriteString(`''`) buf.WriteString(`''`)
s = i + 1 s = i + 1
} }
} }
if buf == nil {
return b
}
l := len(b) l := len(b)
if s < (l - 1) { if s < (l - 1) {
buf.Write(b[s:l]) buf.Write(b[s:l])

13
core/args_test.go Normal file
View File

@ -0,0 +1,13 @@
package core
import "testing"
func TestEscQuote(t *testing.T) {
val := "That's the worst, don''t be calling me's again"
exp := "That''s the worst, don''''t be calling me''s again"
ret := escSQuote([]byte(val))
if exp != string(ret) {
t.Errorf("escSQuote failed: %s", string(ret))
}
}

View File

@ -167,16 +167,16 @@ func (sg *SuperGraph) renderUserQuery(stmts []stmt) (string, error) {
return w.String(), nil return w.String(), nil
} }
func (sg *SuperGraph) hasTablesWithConfig(qc *qcode.QCode, role *Role) bool { // func (sg *SuperGraph) hasTablesWithConfig(qc *qcode.QCode, role *Role) bool {
for _, id := range qc.Roots { // for _, id := range qc.Roots {
t, err := sg.schema.GetTable(qc.Selects[id].Name) // t, err := sg.schema.GetTable(qc.Selects[id].Name)
if err != nil { // if err != nil {
return false // return false
} // }
if r := role.GetTable(t.Name); r == nil { // if r := role.GetTable(t.Name); r == nil {
return false // return false
} // }
} // }
return true // return true
} // }

View File

@ -14,6 +14,11 @@ import (
"github.com/valyala/fasttemplate" "github.com/valyala/fasttemplate"
) )
const (
OpQuery int = iota
OpMutation
)
type extensions struct { type extensions struct {
Tracing *trace `json:"tracing,omitempty"` Tracing *trace `json:"tracing,omitempty"`
} }
@ -329,7 +334,20 @@ func (c *scontext) executeRoleQuery(tx *sql.Tx) (string, error) {
return role, nil return role, nil
} }
func (r *Result) Operation() string { func (r *Result) Operation() int {
switch r.op {
case qcode.QTQuery:
return OpQuery
case qcode.QTMutation, qcode.QTInsert, qcode.QTUpdate, qcode.QTUpsert, qcode.QTDelete:
return OpMutation
default:
return -1
}
}
func (r *Result) OperationName() string {
return r.op.String() return r.op.String()
} }

View File

@ -40,8 +40,12 @@ func TestCockroachDB(t *testing.T) {
stopDatabase := func() { stopDatabase := func() {
fmt.Println("stopping temporary cockroach db") fmt.Println("stopping temporary cockroach db")
if atomic.CompareAndSwapInt32(&stopped, 0, 1) { if atomic.CompareAndSwapInt32(&stopped, 0, 1) {
cmd.Process.Kill() if err := cmd.Process.Kill(); err != nil {
cmd.Process.Wait() log.Fatal(err)
}
if _, err := cmd.Process.Wait(); err != nil {
log.Fatal(err)
}
os.RemoveAll(dir) os.RemoveAll(dir)
} }
} }

View File

@ -382,7 +382,7 @@ func (s *DBSchema) updateSchemaOTMT(
func (s *DBSchema) GetTableNames() []string { func (s *DBSchema) GetTableNames() []string {
var names []string var names []string
for name, _ := range s.t { for name := range s.t {
names = append(names, name) names = append(names, name)
} }
return names return names

View File

@ -29,19 +29,16 @@ func (sg *SuperGraph) initGraphQLEgine() error {
engineSchema := engine.Schema engineSchema := engine.Schema
dbSchema := sg.schema dbSchema := sg.schema
engineSchema.Parse(` if err := engineSchema.Parse(`enum OrderDirection { asc desc }`); err != nil {
enum OrderDirection { return err
asc }
desc
}
`)
gqltype := func(col psql.DBColumn) schema.Type { gqltype := func(col psql.DBColumn) schema.Type {
typeName := typeMap[strings.ToLower(col.Type)] typeName := typeMap[strings.ToLower(col.Type)]
if typeName == "" { if typeName == "" {
typeName = "String" typeName = "String"
} }
var t schema.Type = &schema.TypeName{Ident: schema.Ident{Text: typeName}} var t schema.Type = &schema.TypeName{Name: typeName}
if col.NotNull { if col.NotNull {
t = &schema.NonNull{OfType: t} t = &schema.NonNull{OfType: t}
} }
@ -109,16 +106,16 @@ enum OrderDirection {
Name: expressionTypeName, Name: expressionTypeName,
Fields: schema.InputValueList{ Fields: schema.InputValueList{
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "and"}, Name: "and",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: expressionTypeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: expressionTypeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "or"}, Name: "or",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: expressionTypeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: expressionTypeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "not"}, Name: "not",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: expressionTypeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: expressionTypeName}},
}, },
}, },
} }
@ -133,9 +130,9 @@ enum OrderDirection {
colType := gqltype(col) colType := gqltype(col)
nullableColType := "" nullableColType := ""
if x, ok := colType.(*schema.NonNull); ok { if x, ok := colType.(*schema.NonNull); ok {
nullableColType = x.OfType.(*schema.TypeName).Ident.Text nullableColType = x.OfType.(*schema.TypeName).Name
} else { } else {
nullableColType = colType.(*schema.TypeName).Ident.Text nullableColType = colType.(*schema.TypeName).Name
} }
outputType.Fields = append(outputType.Fields, &schema.Field{ outputType.Fields = append(outputType.Fields, &schema.Field{
@ -198,67 +195,67 @@ enum OrderDirection {
} }
inputType.Fields = append(inputType.Fields, &schema.InputValue{ inputType.Fields = append(inputType.Fields, &schema.InputValue{
Name: schema.Ident{Text: colName}, Name: colName,
Type: colType, Type: colType,
}) })
orderByType.Fields = append(orderByType.Fields, &schema.InputValue{ orderByType.Fields = append(orderByType.Fields, &schema.InputValue{
Name: schema.Ident{Text: colName}, Name: colName,
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "OrderDirection"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "OrderDirection"}},
}) })
scalarExpressionTypesNeeded[nullableColType] = true scalarExpressionTypesNeeded[nullableColType] = true
expressionType.Fields = append(expressionType.Fields, &schema.InputValue{ expressionType.Fields = append(expressionType.Fields, &schema.InputValue{
Name: schema.Ident{Text: colName}, Name: colName,
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: nullableColType + "Expression"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: nullableColType + "Expression"}},
}) })
} }
outputTypeName := &schema.TypeName{Ident: schema.Ident{Text: outputType.Name}} outputTypeName := &schema.TypeName{Name: outputType.Name}
inputTypeName := &schema.TypeName{Ident: schema.Ident{Text: inputType.Name}} inputTypeName := &schema.TypeName{Name: inputType.Name}
pluralOutputTypeName := &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: outputType.Name}}}}} pluralOutputTypeName := &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Name: outputType.Name}}}}
pluralInputTypeName := &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: inputType.Name}}}}} pluralInputTypeName := &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Name: inputType.Name}}}}
args := schema.InputValueList{ args := schema.InputValueList{
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: "To sort or ordering results just use the order_by argument. This can be combined with where, search, etc to build complex queries to fit you needs."}, Desc: schema.Description{Text: "To sort or ordering results just use the order_by argument. This can be combined with where, search, etc to build complex queries to fit you needs."},
Name: schema.Ident{Text: "order_by"}, Name: "order_by",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: orderByType.Name}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: orderByType.Name}},
}, },
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: schema.Ident{Text: "where"}, Name: "where",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: expressionType.Name}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: expressionType.Name}},
}, },
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: schema.Ident{Text: "limit"}, Name: "limit",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "Int"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "Int"}},
}, },
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: schema.Ident{Text: "offset"}, Name: "offset",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "Int"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "Int"}},
}, },
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: schema.Ident{Text: "first"}, Name: "first",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "Int"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "Int"}},
}, },
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: schema.Ident{Text: "last"}, Name: "last",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "Int"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "Int"}},
}, },
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: schema.Ident{Text: "before"}, Name: "before",
Type: &schema.TypeName{Ident: schema.Ident{Text: "String"}}, Type: &schema.TypeName{Name: "String"},
}, },
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: schema.Ident{Text: "after"}, Name: "after",
Type: &schema.TypeName{Ident: schema.Ident{Text: "String"}}, Type: &schema.TypeName{Name: "String"},
}, },
} }
if ti.PrimaryCol != nil { if ti.PrimaryCol != nil {
@ -267,28 +264,28 @@ enum OrderDirection {
t = &schema.NonNull{OfType: t} t = &schema.NonNull{OfType: t}
} }
args = append(args, &schema.InputValue{ args = append(args, &schema.InputValue{
Desc: &schema.Description{Text: "Finds the record by the primary key"}, Desc: schema.Description{Text: "Finds the record by the primary key"},
Name: schema.Ident{Text: "id"}, Name: "id",
Type: t, Type: t,
}) })
} }
if ti.TSVCol != nil { if ti.TSVCol != nil {
args = append(args, &schema.InputValue{ args = append(args, &schema.InputValue{
Desc: &schema.Description{Text: "Performs full text search using a TSV index"}, Desc: schema.Description{Text: "Performs full text search using a TSV index"},
Name: schema.Ident{Text: "search"}, Name: "search",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "String"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "String"}},
}) })
} }
query.Fields = append(query.Fields, &schema.Field{ query.Fields = append(query.Fields, &schema.Field{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: singularName, Name: singularName,
Type: outputTypeName, Type: outputTypeName,
Args: args, Args: args,
}) })
query.Fields = append(query.Fields, &schema.Field{ query.Fields = append(query.Fields, &schema.Field{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: pluralName, Name: pluralName,
Type: pluralOutputTypeName, Type: pluralOutputTypeName,
Args: args, Args: args,
@ -296,19 +293,19 @@ enum OrderDirection {
mutationArgs := append(args, schema.InputValueList{ mutationArgs := append(args, schema.InputValueList{
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: schema.Ident{Text: "insert"}, Name: "insert",
Type: inputTypeName, Type: inputTypeName,
}, },
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: schema.Ident{Text: "update"}, Name: "update",
Type: inputTypeName, Type: inputTypeName,
}, },
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: schema.Ident{Text: "upsert"}, Name: "upsert",
Type: inputTypeName, Type: inputTypeName,
}, },
}...) }...)
@ -322,18 +319,18 @@ enum OrderDirection {
Name: pluralName, Name: pluralName,
Args: append(mutationArgs, schema.InputValueList{ Args: append(mutationArgs, schema.InputValueList{
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: schema.Ident{Text: "inserts"}, Name: "inserts",
Type: pluralInputTypeName, Type: pluralInputTypeName,
}, },
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: schema.Ident{Text: "updates"}, Name: "updates",
Type: pluralInputTypeName, Type: pluralInputTypeName,
}, },
&schema.InputValue{ &schema.InputValue{
Desc: &schema.Description{Text: ""}, Desc: schema.Description{Text: ""},
Name: schema.Ident{Text: "upserts"}, Name: "upserts",
Type: pluralInputTypeName, Type: pluralInputTypeName,
}, },
}...), }...),
@ -341,138 +338,137 @@ enum OrderDirection {
}) })
} }
for typeName, _ := range scalarExpressionTypesNeeded { for typeName := range scalarExpressionTypesNeeded {
expressionType := &schema.InputObject{ expressionType := &schema.InputObject{
Name: typeName + "Expression", Name: typeName + "Expression",
Fields: schema.InputValueList{ Fields: schema.InputValueList{
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "eq"}, Name: "eq",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "equals"}, Name: "equals",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "neq"}, Name: "neq",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "not_equals"}, Name: "not_equals",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "gt"}, Name: "gt",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "greater_than"}, Name: "greater_than",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "lt"}, Name: "lt",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "lesser_than"}, Name: "lesser_than",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "gte"}, Name: "gte",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "greater_or_equals"}, Name: "greater_or_equals",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "lte"}, Name: "lte",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "lesser_or_equals"}, Name: "lesser_or_equals",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "in"}, Name: "in",
Type: &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}}}, Type: &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}}}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "nin"}, Name: "nin",
Type: &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}}}, Type: &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}}}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "not_in"}, Name: "not_in",
Type: &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}}}, Type: &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}}}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "like"}, Name: "like",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "String"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "String"}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "nlike"}, Name: "nlike",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "String"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "String"}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "not_like"}, Name: "not_like",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "String"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "String"}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "ilike"}, Name: "ilike",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "String"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "String"}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "nilike"}, Name: "nilike",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "String"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "String"}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "not_ilike"}, Name: "not_ilike",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "String"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "String"}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "similar"}, Name: "similar",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "String"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "String"}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "nsimilar"}, Name: "nsimilar",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "String"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "String"}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "not_similar"}, Name: "not_similar",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "String"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "String"}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "has_key"}, Name: "has_key",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "has_key_any"}, Name: "has_key_any",
Type: &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}}}, Type: &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}}}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "has_key_all"}, Name: "has_key_all",
Type: &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}}}, Type: &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}}}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "contains"}, Name: "contains",
Type: &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: typeName}}}}}, Type: &schema.NonNull{OfType: &schema.List{OfType: &schema.NonNull{OfType: &schema.TypeName{Name: typeName}}}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "contained_in"}, Name: "contained_in",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "String"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "String"}},
}, },
&schema.InputValue{ &schema.InputValue{
Name: schema.Ident{Text: "is_null"}, Name: "is_null",
Type: &schema.NonNull{OfType: &schema.TypeName{Ident: schema.Ident{Text: "Boolean"}}}, Type: &schema.NonNull{OfType: &schema.TypeName{Name: "Boolean"}},
}, },
}, },
} }
engineSchema.Types[expressionType.Name] = expressionType engineSchema.Types[expressionType.Name] = expressionType
} }
err := engineSchema.ResolveTypes() if err := engineSchema.ResolveTypes(); err != nil {
if err != nil {
return err return err
} }

View File

@ -120,20 +120,20 @@ func buildFn(r Remote) func(http.Header, []byte) ([]byte, error) {
} }
defer res.Body.Close() defer res.Body.Close()
if r.Debug { // if r.Debug {
// reqDump, err := httputil.DumpRequestOut(req, true) // reqDump, err := httputil.DumpRequestOut(req, true)
// if err != nil { // if err != nil {
// return nil, err // return nil, err
// } // }
// resDump, err := httputil.DumpResponse(res, true) // resDump, err := httputil.DumpResponse(res, true)
// if err != nil { // if err != nil {
// return nil, err // return nil, err
// } // }
// logger.Debug().Msgf("Remote Request Debug:\n%s\n%s", // logger.Debug().Msgf("Remote Request Debug:\n%s\n%s",
// reqDump, resDump) // reqDump, resDump)
} // }
if res.StatusCode != 200 { if res.StatusCode != 200 {
return nil, return nil,

View File

@ -104,7 +104,7 @@ query {
</div> </div>
<div class="text-2xl md:text-3xl"> <div class="text-2xl md:text-3xl">
Super Graph is a library and service that fetches data from any Postgres database using just GraphQL. No more struggling with ORMs and SQL to wrangle data out of the database. No more having to figure out the right joins or making ineffiient queries. However complex the GraphQL, Super Graph will always generate just one single efficient SQL query. The goal is to save you time and money so you can focus on you're apps core value. Super Graph is a library and service that fetches data from any Postgres database using just GraphQL. No more struggling with ORMs and SQL to wrangle data out of the database. No more having to figure out the right joins or making inefficient queries. However complex the GraphQL, Super Graph will always generate just one single efficient SQL query. The goal is to save you time and money so you can focus on you're apps core value.
</div> </div>
</div> </div>
</div> </div>

View File

@ -10,7 +10,7 @@ longTagline: Get an instant high performance GraphQL API for Postgres. No code n
actionText: Get Started, Free, Open Source → actionText: Get Started, Free, Open Source →
actionLink: /guide actionLink: /guide
description: Super Graph can automatically learn a Postgres database and instantly serve it as a fast and secured GraphQL API. It comes with tools to create a new app and manage it's database. You get it all, a very productive developer and a highly scalable app backend. It's designed to work well on serverless platforms by Google, AWS, Microsoft, etc. The goal is to save you a ton of time and money so you can focus on you're apps core value. description: Super Graph can automatically learn a Postgres database and instantly serve it as a fast and secured GraphQL API. It comes with tools to create a new app and manage it's database. You get it all, a very productive developer and a highly scalable app backend. It's designed to work well on serverless platforms by Google, AWS, Microsoft, etc. The goal is to save you a ton of time and money so you can focus on your apps core value.
features: features:
- title: Simple - title: Simple

View File

@ -32,7 +32,7 @@ For this to work you have to ensure that the option `:domain => :all` is added t
### With an NGINX loadbalancer ### With an NGINX loadbalancer
If you're infrastructure is fronted by NGINX then it should be configured so that all requests to your GraphQL API path are proxyed to Super Graph. In the example NGINX config below all requests to the path `/api/v1/graphql` are routed to wherever you have Super Graph installed within your architecture. This example is derived from the config file example at [/microservices-nginx-gateway/nginx.conf](https://github.com/launchany/microservices-nginx-gateway/blob/master/nginx.conf) If your infrastructure is fronted by NGINX then it should be configured so that all requests to your GraphQL API path are proxyed to Super Graph. In the example NGINX config below all requests to the path `/api/v1/graphql` are routed to wherever you have Super Graph installed within your architecture. This example is derived from the config file example at [/microservices-nginx-gateway/nginx.conf](https://github.com/launchany/microservices-nginx-gateway/blob/master/nginx.conf)
::: tip NGINX with sub-domain ::: tip NGINX with sub-domain
Yes, NGINX is very flexible and you can configure it to keep Super Graph a subdomain instead of on the same top level domain. I'm sure a little Googleing will get you some great example configs for that. Yes, NGINX is very flexible and you can configure it to keep Super Graph a subdomain instead of on the same top level domain. I'm sure a little Googleing will get you some great example configs for that.

View File

@ -1069,7 +1069,7 @@ mutation {
### Pagination ### Pagination
This is a must have feature of any API. When you want your users to go thought a list page by page or implement some fancy infinite scroll you're going to need pagination. There are two ways to paginate in Super Graph. This is a must have feature of any API. When you want your users to go through a list page by page or implement some fancy infinite scroll you're going to need pagination. There are two ways to paginate in Super Graph.
Limit-Offset Limit-Offset
This is simple enough but also inefficient when working with a large number of total items. Limit, limits the number of items fetched and offset is the point you want to fetch from. The below query will fetch 10 results at a time starting with the 100th item. You will have to keep updating offset (110, 120, 130, etc ) to walk thought the results so make offset a variable. This is simple enough but also inefficient when working with a large number of total items. Limit, limits the number of items fetched and offset is the point you want to fetch from. The below query will fetch 10 results at a time starting with the 100th item. You will have to keep updating offset (110, 120, 130, etc ) to walk thought the results so make offset a variable.
@ -1085,7 +1085,7 @@ query {
``` ```
#### Cursor #### Cursor
This is a powerful and highly efficient way to paginate though a large number of results. Infact it does not matter how many total results there are this will always be lighting fast. You can use a cursor to walk forward of backward though the results. If you plan to implement infinite scroll this is the option you should choose. This is a powerful and highly efficient way to paginate a large number of results. Infact it does not matter how many total results there are this will always be lighting fast. You can use a cursor to walk forward or backward through the results. If you plan to implement infinite scroll this is the option you should choose.
When going this route the results will contain a cursor value this is an encrypted string that you don't have to worry about just pass this back in to the next API call and you'll received the next set of results. The cursor value is encrypted since its contents should only matter to Super Graph and not the client. Also since the primary key is used for this feature it's possible you might not want to leak it's value to clients. When going this route the results will contain a cursor value this is an encrypted string that you don't have to worry about just pass this back in to the next API call and you'll received the next set of results. The cursor value is encrypted since its contents should only matter to Super Graph and not the client. Also since the primary key is used for this feature it's possible you might not want to leak it's value to clients.

5
go.mod
View File

@ -8,11 +8,11 @@ require (
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b
github.com/brianvoe/gofakeit/v5 v5.2.0 github.com/brianvoe/gofakeit/v5 v5.2.0
github.com/cespare/xxhash/v2 v2.1.1 github.com/cespare/xxhash/v2 v2.1.1
github.com/chirino/graphql v0.0.0-20200419184546-f015b9dab85d github.com/chirino/graphql v0.0.0-20200430165312-293648399b1a
github.com/daaku/go.zipexe v1.0.1 // indirect github.com/daaku/go.zipexe v1.0.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/dlclark/regexp2 v1.2.0 // indirect github.com/dlclark/regexp2 v1.2.0 // indirect
github.com/dop251/goja v0.0.0-20200414142002-77e84ffb8c65 github.com/dop251/goja v0.0.0-20200424152103-d0b8fda54cd0
github.com/fsnotify/fsnotify v1.4.9 github.com/fsnotify/fsnotify v1.4.9
github.com/garyburd/redigo v1.6.0 github.com/garyburd/redigo v1.6.0
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
@ -34,7 +34,6 @@ require (
github.com/valyala/fasttemplate v1.1.0 github.com/valyala/fasttemplate v1.1.0
go.uber.org/zap v1.14.1 go.uber.org/zap v1.14.1
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904 golang.org/x/crypto v0.0.0-20200414173820-0848c9571904
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 // indirect golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect

17
go.sum
View File

@ -27,8 +27,8 @@ github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chirino/graphql v0.0.0-20200419184546-f015b9dab85d h1:JnYHwwRhFmQ8DeyfqmIrzpkkxnZ+iT5V1CUd3Linin0= github.com/chirino/graphql v0.0.0-20200430165312-293648399b1a h1:WVu7r2vwlrBVmunbSSU+9/3M3AgsQyhE49CKDjHiFq4=
github.com/chirino/graphql v0.0.0-20200419184546-f015b9dab85d/go.mod h1:+34LPrbHFfKVDPsNfi445UArMEjbeTlCm7C+OpdC7IU= github.com/chirino/graphql v0.0.0-20200430165312-293648399b1a/go.mod h1:wQjjxFMFyMlsWh4Z3nMuHQtevD4Ul9UVQSnz1JOLuP8=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
@ -55,8 +55,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dlclark/regexp2 v1.2.0 h1:8sAhBGEM0dRWogWqWyQeIJnxjWO6oIjl8FKqREDsGfk= github.com/dlclark/regexp2 v1.2.0 h1:8sAhBGEM0dRWogWqWyQeIJnxjWO6oIjl8FKqREDsGfk=
github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dop251/goja v0.0.0-20200414142002-77e84ffb8c65 h1:Nud597JuGCF/MScrb6NNVDRgmuk8X7w3pFc5GvSsm5E= github.com/dop251/goja v0.0.0-20200424152103-d0b8fda54cd0 h1:EfFAcaAwGai/wlDCWwIObHBm3T2C2CCPX/SaS0fpOJ4=
github.com/dop251/goja v0.0.0-20200414142002-77e84ffb8c65/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA= github.com/dop251/goja v0.0.0-20200424152103-d0b8fda54cd0/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/friendsofgo/graphiql v0.2.2/go.mod h1:8Y2kZ36AoTGWs78+VRpvATyt3LJBx0SZXmay80ZTRWo= github.com/friendsofgo/graphiql v0.2.2/go.mod h1:8Y2kZ36AoTGWs78+VRpvATyt3LJBx0SZXmay80ZTRWo=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@ -90,7 +90,7 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGa
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gosimple/slug v1.9.0 h1:r5vDcYrFz9BmfIAMC829un9hq7hKM4cHUrsv36LbEqs= github.com/gosimple/slug v1.9.0 h1:r5vDcYrFz9BmfIAMC829un9hq7hKM4cHUrsv36LbEqs=
github.com/gosimple/slug v1.9.0/go.mod h1:AMZ+sOVe65uByN3kgEyf9WEBKBCSS+dJjMX9x4vDJbg= github.com/gosimple/slug v1.9.0/go.mod h1:AMZ+sOVe65uByN3kgEyf9WEBKBCSS+dJjMX9x4vDJbg=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
@ -189,8 +189,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229 h1:E2B8qYyeSgv5MXpmzZXRNp8IAQ4vjxIjhpAf5hv/tAg= github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229 h1:E2B8qYyeSgv5MXpmzZXRNp8IAQ4vjxIjhpAf5hv/tAg=
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E= github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.7.0 h1:7utD74fnzVc/cpcyy8sjrlFr5vYpypUixARcHIMIGuI= github.com/pelletier/go-toml v1.7.0 h1:7utD74fnzVc/cpcyy8sjrlFr5vYpypUixARcHIMIGuI=
@ -330,8 +330,6 @@ golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -352,7 +350,6 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456 h1:ng0gs1AKnRRuEMZoTLLlbOd+C17zUDepwGQBb/n+JVg= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456 h1:ng0gs1AKnRRuEMZoTLLlbOd+C17zUDepwGQBb/n+JVg=
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HXxFpW2sdCiP8MJSKLQY= golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HXxFpW2sdCiP8MJSKLQY=
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=

View File

@ -46,6 +46,7 @@ type Serv struct {
AllowedOrigins []string `mapstructure:"cors_allowed_origins"` AllowedOrigins []string `mapstructure:"cors_allowed_origins"`
DebugCORS bool `mapstructure:"cors_debug"` DebugCORS bool `mapstructure:"cors_debug"`
APIPath string `mapstructure:"api_path"` APIPath string `mapstructure:"api_path"`
CacheControl string `mapstructure:"cache_control"`
Auth auth.Auth Auth auth.Auth
Auths []auth.Auth Auths []auth.Auth

View File

@ -26,13 +26,12 @@ var (
) )
var ( var (
log *_log.Logger // logger log *_log.Logger // logger
zlog *zap.Logger // fast logger zlog *zap.Logger // fast logger
logLevel int // log level logLevel int // log level
conf *Config // parsed config conf *Config // parsed config
confPath string // path to the config file confPath string // path to the config file
db *sql.DB // database connection pool db *sql.DB // database connection pool
secretKey [32]byte // encryption key
) )
func Cmd() { func Cmd() {

View File

@ -415,6 +415,7 @@ func setFakeFuncs(f *goja.Object) {
//f.Set("programming_language", gofakeit.ProgrammingLanguage) //f.Set("programming_language", gofakeit.ProgrammingLanguage)
} }
//nolint: errcheck
func setUtilFuncs(f *goja.Object) { func setUtilFuncs(f *goja.Object) {
// Slugs // Slugs
f.Set("make_slug", slug.Make) f.Set("make_slug", slug.Make)

View File

@ -7,6 +7,7 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"github.com/dosco/super-graph/core"
"github.com/dosco/super-graph/internal/serv/internal/auth" "github.com/dosco/super-graph/internal/serv/internal/auth"
"github.com/rs/cors" "github.com/rs/cors"
"go.uber.org/zap" "go.uber.org/zap"
@ -76,7 +77,7 @@ func apiV1(w http.ResponseWriter, r *http.Request) {
doLog := true doLog := true
res, err := sg.GraphQL(ct, req.Query, req.Vars) res, err := sg.GraphQL(ct, req.Query, req.Vars)
if !conf.Production && res.QueryName() == "IntrospectionQuery" { if !conf.Production && res.QueryName() == introspectionQuery {
doLog = false doLog = false
} }
@ -84,15 +85,20 @@ func apiV1(w http.ResponseWriter, r *http.Request) {
log.Printf("DBG query %s: %s", res.QueryName(), res.SQL()) log.Printf("DBG query %s: %s", res.QueryName(), res.SQL())
} }
if err != nil { if err == nil {
renderErr(w, err) if len(conf.CacheControl) != 0 && res.Operation() == core.OpQuery {
} else { w.Header().Set("Cache-Control", conf.CacheControl)
}
//nolint: errcheck
json.NewEncoder(w).Encode(res) json.NewEncoder(w).Encode(res)
} else {
renderErr(w, err)
} }
if doLog && logLevel >= LogLevelInfo { if doLog && logLevel >= LogLevelInfo {
zlog.Info("success", zlog.Info("success",
zap.String("op", res.Operation()), zap.String("op", res.OperationName()),
zap.String("name", res.QueryName()), zap.String("name", res.QueryName()),
zap.String("role", res.Role()), zap.String("role", res.Role()),
) )

View File

@ -1,37 +0,0 @@
package serv
import "net/http"
//nolint: errcheck
func introspect(w http.ResponseWriter) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{
"data": {
"__schema": {
"queryType": {
"name": "Query"
},
"mutationType": null,
"subscriptionType": null
}
},
"extensions":{
"tracing":{
"version":1,
"startTime":"2019-06-04T19:53:31.093Z",
"endTime":"2019-06-04T19:53:31.108Z",
"duration":15219720,
"execution": {
"resolvers": [{
"path": ["__schema"],
"parentType": "Query",
"fieldName": "__schema",
"returnType": "__Schema!",
"startOffset": 50950,
"duration": 17187
}]
}
}
}
}`))
}

View File

@ -46,6 +46,13 @@ cors_allowed_origins: ["*"]
# Debug Cross Origin Resource Sharing requests # Debug Cross Origin Resource Sharing requests
cors_debug: false cors_debug: false
# Default API path prefix is /api you can change it if you like
# api_path: "/data"
# Cache-Control header can help cache queries if your CDN supports cache-control
# on POST requests (does not work with not mutations)
# cache_control: "public, max-age=300, s-maxage=600"
# Postgres related environment Variables # Postgres related environment Variables
# SG_DATABASE_HOST # SG_DATABASE_HOST
# SG_DATABASE_PORT # SG_DATABASE_PORT

View File

@ -49,6 +49,13 @@ reload_on_config_change: false
# Debug Cross Origin Resource Sharing requests # Debug Cross Origin Resource Sharing requests
# cors_debug: false # cors_debug: false
# Default API path prefix is /api you can change it if you like
# api_path: "/data"
# Cache-Control header can help cache queries if your CDN supports cache-control
# on POST requests (does not work with not mutations)
# cache_control: "public, max-age=300, s-maxage=600"
# Postgres related environment Variables # Postgres related environment Variables
# SG_DATABASE_HOST # SG_DATABASE_HOST
# SG_DATABASE_PORT # SG_DATABASE_PORT