Fix bug related to 'anon' role prepared statements
This commit is contained in:
parent
7930719eaa
commit
6c240e21b4
|
@ -17,6 +17,10 @@ const (
|
||||||
closeBlock = 500
|
closeBlock = 500
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrAllTablesSkipped = errors.New("all tables skipped. cannot render query")
|
||||||
|
)
|
||||||
|
|
||||||
type Variables map[string]json.RawMessage
|
type Variables map[string]json.RawMessage
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
@ -107,7 +111,7 @@ func (co *Compiler) compileQuery(qc *qcode.QCode, w io.Writer, vars Variables) (
|
||||||
io.WriteString(c.w, `) as "__root" FROM `)
|
io.WriteString(c.w, `) as "__root" FROM `)
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
return 0, errors.New("all tables skipped. cannot render query")
|
return 0, ErrAllTablesSkipped
|
||||||
}
|
}
|
||||||
|
|
||||||
var ignored uint32
|
var ignored uint32
|
||||||
|
|
|
@ -90,7 +90,7 @@ func buildMultiStmt(gql, vars []byte) ([]stmt, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(conf.RolesQuery) == 0 {
|
if len(conf.RolesQuery) == 0 {
|
||||||
return buildRoleStmt(gql, vars, "user")
|
return nil, errors.New("roles_query not defined")
|
||||||
}
|
}
|
||||||
|
|
||||||
stmts := make([]stmt, 0, len(conf.Roles))
|
stmts := make([]stmt, 0, len(conf.Roles))
|
||||||
|
@ -99,6 +99,7 @@ func buildMultiStmt(gql, vars []byte) ([]stmt, error) {
|
||||||
for i := 0; i < len(conf.Roles); i++ {
|
for i := 0; i < len(conf.Roles); i++ {
|
||||||
role := &conf.Roles[i]
|
role := &conf.Roles[i]
|
||||||
|
|
||||||
|
// skip anon as it's not included in the combined multi-statement
|
||||||
if role.Name == "anon" {
|
if role.Name == "anon" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/dosco/super-graph/allow"
|
"github.com/dosco/super-graph/allow"
|
||||||
|
"github.com/dosco/super-graph/psql"
|
||||||
"github.com/dosco/super-graph/qcode"
|
"github.com/dosco/super-graph/qcode"
|
||||||
"github.com/jackc/pgconn"
|
"github.com/jackc/pgconn"
|
||||||
"github.com/jackc/pgx/v4"
|
"github.com/jackc/pgx/v4"
|
||||||
|
@ -120,6 +121,9 @@ func prepareStmt(item allow.Item) error {
|
||||||
logger.Debug().Msg("Prepared statement for role: anon")
|
logger.Debug().Msg("Prepared statement for role: anon")
|
||||||
|
|
||||||
stmts2, err := buildRoleStmt(q, vars, "anon")
|
stmts2, err := buildRoleStmt(q, vars, "anon")
|
||||||
|
if err == psql.ErrAllTablesSkipped {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,11 @@ func Do(log func(string, ...interface{}), additional ...dir) error {
|
||||||
// Ensure that we use the correct events, as they are not uniform across
|
// Ensure that we use the correct events, as they are not uniform across
|
||||||
// platforms. See https://github.com/fsnotify/fsnotify/issues/74
|
// platforms. See https://github.com/fsnotify/fsnotify/issues/74
|
||||||
|
|
||||||
if conf != nil && !conf.Production && strings.HasSuffix(event.Name, "/allow.list") {
|
if conf != nil && strings.HasSuffix(event.Name, "/allow.list") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if conf.Production {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,11 @@ auth_fail_block: true
|
||||||
# Latency tracing for database queries and remote joins
|
# Latency tracing for database queries and remote joins
|
||||||
# the resulting latency information is returned with the
|
# the resulting latency information is returned with the
|
||||||
# response
|
# response
|
||||||
enable_tracing: true
|
enable_tracing: false
|
||||||
|
|
||||||
|
# Watch the config folder and reload Super Graph
|
||||||
|
# with the new configs when a change is detected
|
||||||
|
reload_on_config_change: false
|
||||||
|
|
||||||
# File that points to the database seeding script
|
# File that points to the database seeding script
|
||||||
# seed_file: seed.js
|
# seed_file: seed.js
|
||||||
|
|
Loading…
Reference in New Issue