Skip to content

Commit

Permalink
fixed some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshil Goel committed Aug 21, 2023
1 parent 5a8ac03 commit ab496a9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
22 changes: 12 additions & 10 deletions graphql/schema/gqlschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2333,17 +2333,19 @@ func getFieldsWithoutIDType(schema *ast.Schema, defn *ast.Definition,
// This function check if given gql field has multiple language tags
func isMultiLangField(fld *ast.FieldDefinition, isMutationInput bool) bool {
dgDirective := fld.Directives.ForName(dgraphDirective)
if dgDirective != nil {
pred := dgDirective.Arguments.ForName("pred")
if pred != nil {
if strings.Contains(pred.Value.Raw, "@") {
langs := strings.Split(pred.Value.Raw, "@")[1]
if isMutationInput {
return strings.Contains(langs, ":") || langs == "."
}
return strings.Contains(langs, ":")
}
if dgDirective == nil {
return false
}
pred := dgDirective.Arguments.ForName("pred")
if pred == nil {
return false
}
if strings.Contains(pred.Value.Raw, "@") {
langs := strings.Split(pred.Value.Raw, "@")[1]
if isMutationInput {
return strings.Contains(langs, ":") || langs == "."
}
return strings.Contains(langs, ":")
}
return false
}
Expand Down
11 changes: 11 additions & 0 deletions graphql/schema/gqlschema_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2889,6 +2889,17 @@ invalid_schemas:
{ "message": "Type TwitterUser; @lambdaOnMutate directive not allowed along with @remote directive.", "locations": [{"line": 1, "column": 27}]}
]

- name: "language tag field can't contain more than on @"
input: |
type Person {
name: String!
nameHi: String @dgraph(pred:"Person.name@hi@en")
}
errlist: [
{ "message": "Type Person; Field nameHi: multiple language tag not supported",
"locations": [ { "line": 3, "column": 19 } ] },
]

- name: "language tag field should be of String type"
input: |
type Person {
Expand Down
9 changes: 8 additions & 1 deletion graphql/schema/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,8 @@ func dgraphDirectiveValidation(sch *ast.Schema, typ *ast.Definition, field *ast.
return errs
}

tags := strings.Split(predArg.Value.Raw, "@")[1]
allTags := strings.Split(predArg.Value.Raw, "@")
tags := allTags[1]
if tags == "*" {
errs = append(errs, gqlerror.ErrorPosf(dir.Position, "Type %s; Field %s: `*` language tag not"+
" supported in GraphQL", typ.Name, field.Name))
Expand All @@ -1261,6 +1262,12 @@ func dgraphDirectiveValidation(sch *ast.Schema, typ *ast.Definition, field *ast.
" tag not supported", typ.Name, field.Name))
return errs
}
fmt.Println(field.Name)
if len(allTags) > 2 {
errs = append(errs, gqlerror.ErrorPosf(dir.Position, "Type %s; Field %s: multiple language"+
" tag not supported", typ.Name, field.Name))
return errs
}

}
return nil
Expand Down
3 changes: 1 addition & 2 deletions graphql/schema/schemagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,7 @@ func genDgSchema(gqlSch *ast.Schema, definitions []string,
if f.lang {
langStr = " @lang"
}
fmt.Fprintf(&preds, "%s: %s%s%s %s%s.\n", fld.name, f.typ, indexStr, langStr, f.upsert,
f.reverse)
fmt.Fprintf(&preds, "%s: %s%s%s %s%s.\n", fld.name, f.typ, indexStr, langStr, f.upsert, f.reverse)
predWritten[fld.name] = true
}
}
Expand Down

0 comments on commit ab496a9

Please sign in to comment.