Skip to content

Commit

Permalink
resolved review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaji-kharse committed Aug 27, 2024
1 parent 655af94 commit b5f7bfd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions graphql/resolve/mutation_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ import (
)

const (
MutationQueryVar = "x"
MutationQueryVarUID = "uid(x)"
updateMutationCondition = `gt(len(x), 0)`
MutationQueryVar = "x"
MutationQueryVarUID = "uid(x)"
updateMutationCondition = `gt(len(x), 0)`
defaultDirectiveUpdateAct = "update"
defaultDirectiveAddAct = "add"
)

// Enum passed on to rewriteObject function.
Expand Down Expand Up @@ -1587,7 +1589,7 @@ func rewriteObject(
}
}

action := "update"
action := defaultDirectiveUpdateAct

// This is not an XID reference. This is also not a UID reference.
// This is definitely a new node.
Expand Down Expand Up @@ -1637,7 +1639,7 @@ func rewriteObject(
// "_:Project2" . myUID will store the variable generated to reference this node.
newObj["dgraph.type"] = dgraphTypes
newObj["uid"] = myUID
action = "add"
action = defaultDirectiveAddAct
}

// Now we know whether this is a new node or not, we can set @default(add/update) fields
Expand Down
6 changes: 6 additions & 0 deletions graphql/schema/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,12 @@ func lambdaDirectiveValidation(sch *ast.Schema,
return errs
}

// defaultDirectiveValidation will prevents use of @default on:
// Types with @remote directive
// Fields of type ID
// Fields that are not scalar types (Int, Float, String, Boolean, DateTime) or an enum
// Fields that are list types (ie `[String])
// Fields with @id, @custom, @lambda
func defaultDirectiveValidation(sch *ast.Schema,
typ *ast.Definition,
field *ast.FieldDefinition,
Expand Down

0 comments on commit b5f7bfd

Please sign in to comment.