From b5f7bfddd72f1141084b3d8f9cd085a2b96cc9d7 Mon Sep 17 00:00:00 2001 From: shivaji-dgraph Date: Tue, 27 Aug 2024 12:26:06 +0530 Subject: [PATCH] resolved review comments --- graphql/resolve/mutation_rewriter.go | 12 +++++++----- graphql/schema/rules.go | 6 ++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/graphql/resolve/mutation_rewriter.go b/graphql/resolve/mutation_rewriter.go index 9ea5e843f98..808267885b9 100644 --- a/graphql/resolve/mutation_rewriter.go +++ b/graphql/resolve/mutation_rewriter.go @@ -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. @@ -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. @@ -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 diff --git a/graphql/schema/rules.go b/graphql/schema/rules.go index 77fcfb740eb..4f89a121914 100644 --- a/graphql/schema/rules.go +++ b/graphql/schema/rules.go @@ -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,