Skip to content

Commit

Permalink
Add a hook to determine if it's an updating clause
Browse files Browse the repository at this point in the history
  • Loading branch information
kpom-specter committed Dec 23, 2024
1 parent ae4156f commit eedb546
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/api/src/queries/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ type PreparedQuery struct {
}

func (s *GraphQuery) PrepareCypherQuery(rawCypher string) (PreparedQuery, error) {

var (
cypherFilters = []frontend.Visitor{
&frontend.ExplicitProcedureInvocationFilter{},
Expand All @@ -380,6 +381,8 @@ func (s *GraphQuery) PrepareCypherQuery(rawCypher string) (PreparedQuery, error)

// If cypher mutations are disabled, we want to add the updating clause filter to properly error as unsupported query
if !s.EnableCypherMutations {
cypherFilters = append(cypherFilters, &frontend.UpdatingNotAllowedClauseFilter{})
} else {
cypherFilters = append(cypherFilters, &frontend.UpdatingClauseFilter{})
}

Expand Down
11 changes: 10 additions & 1 deletion packages/go/cypher/frontend/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
// TODO: Review if relying on a deny model is less secure than explicit allow
func DefaultCypherContext() *Context {
return NewContext(
&UpdatingNotAllowedClauseFilter{},
&UpdatingClauseFilter{},
&ExplicitProcedureInvocationFilter{},
&ImplicitProcedureInvocationFilter{},
Expand Down Expand Up @@ -56,10 +57,18 @@ func (s *SpecifiedParametersFilter) EnterOC_Parameter(ctx *parser.OC_ParameterCo
s.ctx.AddErrors(ErrUserSpecifiedParametersNotSupported)
}

type UpdatingNotAllowedClauseFilter struct {
BaseVisitor
}

func (s *UpdatingNotAllowedClauseFilter) EnterOC_UpdatingClause(ctx *parser.OC_UpdatingClauseContext) {
s.ctx.AddErrors(ErrUpdateClauseNotSupported)
}

type UpdatingClauseFilter struct {
BaseVisitor
}

func (s *UpdatingClauseFilter) EnterOC_UpdatingClause(ctx *parser.OC_UpdatingClauseContext) {
s.ctx.AddErrors(ErrUpdateClauseNotSupported)
// Do something that marks this as an updating clause to check later (in pattern.go)
}

0 comments on commit eedb546

Please sign in to comment.