Skip to content

Commit

Permalink
Added lang support
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshil Goel committed Sep 7, 2023
1 parent 4c9448a commit bf5afe5
Show file tree
Hide file tree
Showing 17 changed files with 551 additions and 67 deletions.
2 changes: 2 additions & 0 deletions graphql/e2e/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ func RunAll(t *testing.T) {
t.Run("query id directive with int", idDirectiveWithInt)
t.Run("query id directive with int64", idDirectiveWithInt64)
t.Run("query filter ID values coercion to List", queryFilterWithIDInputCoercion)
t.Run("query multiple language Fields", queryMultipleLangFields)
t.Run("query @id field with interface arg on interface", queryWithIDFieldAndInterfaceArg)

// mutation tests
Expand Down Expand Up @@ -928,6 +929,7 @@ func RunAll(t *testing.T) {
t.Run("input coercion to list", inputCoerciontoList)
t.Run("multiple external Id's tests", multipleXidsTests)
t.Run("Upsert Mutation Tests", upsertMutationTests)
t.Run("Update language tag fields", updateLangTagFields)
t.Run("add mutation with @id field and interface arg", addMutationWithIDFieldHavingInterfaceArg)

// error tests
Expand Down
64 changes: 64 additions & 0 deletions graphql/e2e/common/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6038,6 +6038,70 @@ func upsertMutationTests(t *testing.T) {
deleteState(t, filter, 2, nil)
}

func updateLangTagFields(t *testing.T) {
addPersonParams := &GraphQLParams{
Query: `
mutation addPerson($person: [AddPersonInput!]!) {
addPerson(input: $person) {
numUids
}
}`,
}
addPersonParams.Variables = map[string]interface{}{"person": []interface{}{
map[string]interface{}{
"name": "Juliet",
"nameHi": "जूलियट",
"nameZh": "朱丽叶",
},
},
}
gqlResponse := addPersonParams.ExecuteAsPost(t, GraphqlURL)
RequireNoGQLErrors(t, gqlResponse)
// update Person using language tag field
updatePersonParams := &GraphQLParams{
Query: `
mutation updatePerson {
updatePerson(
input: {
filter: { nameHi: { eq: "जूलियट" } }
set: { nameHi: "जूली", nameZh: "朱丽叶" }
}
) {
numUids
}
}`,
}
gqlResponse = updatePersonParams.ExecuteAsPost(t, GraphqlURL)
RequireNoGQLErrors(t, gqlResponse)

queryPerson := &GraphQLParams{
Query: `
query {
queryPerson(filter: { name: { eq: "Juliet" } }) {
name
nameZh
nameHi
}
}`,
}
gqlResponse = queryPerson.ExecuteAsPost(t, GraphqlURL)
RequireNoGQLErrors(t, gqlResponse)

queryPersonExpected := `
{
"queryPerson": [
{
"name": "Juliet",
"nameZh": "朱丽叶",
"nameHi": "जूली"
}
]
}`

testutil.CompareJSON(t, queryPersonExpected, string(gqlResponse.Data))
DeleteGqlType(t, "Person", map[string]interface{}{}, 1, nil)
}

func addMutationWithIDFieldHavingInterfaceArg(t *testing.T) {
// add data successfully for different implementing types
tcases := []struct {
Expand Down
97 changes: 97 additions & 0 deletions graphql/e2e/common/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3928,6 +3928,103 @@ func idDirectiveWithInt(t *testing.T) {
require.JSONEq(t, expected, string(response.Data))
}

func queryMultipleLangFields(t *testing.T) {
// add three Persons
addPersonParams := &GraphQLParams{
Query: `
mutation addPerson($person: [AddPersonInput!]!) {
addPerson(input: $person) {
numUids
}
}`,
Variables: map[string]interface{}{"person": []interface{}{
map[string]interface{}{
"name": "Bob",
"professionEn": "writer",
},
map[string]interface{}{
"name": "Alice",
"nameHi": "ऐलिस",
"professionEn": "cricketer",
},
map[string]interface{}{
"name": "Juliet",
"nameHi": "जूलियट",
"nameZh": "朱丽叶",
"professionEn": "singer",
},
}},
}

gqlResponse := addPersonParams.ExecuteAsPost(t, GraphqlURL)
RequireNoGQLErrors(t, gqlResponse)

queryPerson := &GraphQLParams{
Query: `
query {
queryPerson(
filter: {
or: [
{ name: { eq: "Bob" } }
{ nameHi: { eq: "ऐलिस" } }
{ nameZh: { eq: "朱丽叶" } }
]
}
order: { desc: nameHi }
) {
name
nameZh
nameHi
nameHiZh
nameZhHi
nameHi_Zh_Untag
name_Untag_AnyLang
professionEn
}
}`,
}
gqlResponse = queryPerson.ExecuteAsPost(t, GraphqlURL)
RequireNoGQLErrors(t, gqlResponse)
queryPersonExpected := `
{
"queryPerson": [
{
"name":"Juliet",
"nameZh":"朱丽叶",
"nameHi":"जूलियट",
"nameHiZh":"जूलियट",
"nameZhHi":"朱丽叶",
"nameHi_Zh_Untag":"जूलियट",
"name_Untag_AnyLang":"Juliet",
"professionEn":"singer"
},
{
"name":"Alice",
"nameZh":null,
"nameHi":"ऐलिस",
"nameHiZh":"ऐलिस",
"nameZhHi":"ऐलिस",
"nameHi_Zh_Untag":"ऐलिस",
"name_Untag_AnyLang":"Alice",
"professionEn":"cricketer"
},
{ "name":"Bob",
"nameZh":null,
"nameHi":null,
"nameHiZh":null,
"nameZhHi":null,
"nameHi_Zh_Untag":"Bob",
"name_Untag_AnyLang":"Bob",
"professionEn":"writer"
}
]
}`

JSONEqGraphQL(t, queryPersonExpected, string(gqlResponse.Data))
// Cleanup
DeleteGqlType(t, "Person", map[string]interface{}{}, 3, nil)
}

func queryWithIDFieldAndInterfaceArg(t *testing.T) {
// add library member
addLibraryMemberParams := &GraphQLParams{
Expand Down
12 changes: 12 additions & 0 deletions graphql/e2e/directives/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ type Person1 {
friends: [Person1] @hasInverse(field: friends)
}

type Person {
id: ID!
name: String! @search(by: [hash])
nameHi: String @dgraph(pred:"Person.name@hi") @search(by: [hash])
nameZh: String @dgraph(pred:"Person.name@zh") @search(by: [hash])
nameHiZh: String @dgraph(pred:"Person.name@hi:zh")
nameZhHi: String @dgraph(pred:"Person.name@zh:hi")
nameHi_Zh_Untag: String @dgraph(pred:"Person.name@hi:zh:.")
name_Untag_AnyLang: String @dgraph(pred:"Person.name@.") @search(by: [hash])
professionEn: String @dgraph(pred:"Person.profession@en")
}

# union testing - start
enum AnimalCategory {
Fish
Expand Down
25 changes: 25 additions & 0 deletions graphql/e2e/directives/schema_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@
"predicate": "Employer.worker",
"type": "uid"
},
{
"lang": true,
"predicate": "Person.profession",
"type": "string"
},
{
"index": true,
"lang": true,
"predicate": "Person.name",
"tokenizer": [
"hash"
],
"type": "string"
},
{
"predicate": "Book.chapters",
"type": "uid",
Expand Down Expand Up @@ -1003,6 +1017,17 @@
],
"name": "Home"
},
{
"fields": [
{
"name": "Person.name"
},
{
"name": "Person.profession"
}
],
"name": "Person"
},
{
"fields": [
{
Expand Down
11 changes: 9 additions & 2 deletions graphql/e2e/normal/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,15 @@ type Student implements People {
}

type Person @withSubscription{
id: ID!
name: String!
id: ID!
name: String! @search(by: [hash])
nameHi: String @dgraph(pred:"Person.name@hi") @search(by: [hash])
nameZh: String @dgraph(pred:"Person.name@zh") @search(by: [hash])
nameHiZh: String @dgraph(pred:"Person.name@hi:zh")
nameZhHi: String @dgraph(pred:"Person.name@zh:hi")
nameHi_Zh_Untag: String @dgraph(pred:"Person.name@hi:zh:.")
name_Untag_AnyLang: String @dgraph(pred:"Person.name@.") @search(by: [hash])
professionEn: String @dgraph(pred:"Person.profession@en")
}

"""
Expand Down
29 changes: 21 additions & 8 deletions graphql/e2e/normal/schema_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,17 @@
"upsert": true
},
{
"lang": true,
"predicate": "Person.profession",
"type": "string"
},
{
"index": true,
"lang": true,
"predicate": "Person.name",
"tokenizer": [
"hash"
],
"type": "string"
},
{
Expand Down Expand Up @@ -1191,14 +1201,6 @@
],
"name": "People"
},
{
"fields": [
{
"name": "Person.name"
}
],
"name": "Person"
},
{
"fields": [
{
Expand Down Expand Up @@ -1619,6 +1621,17 @@
}
],
"name": "LibraryMember"
},
{
"fields": [
{
"name": "Person.name"
},
{
"name": "Person.profession"
}
],
"name": "Person"
}
]
}
21 changes: 21 additions & 0 deletions graphql/resolve/add_mutation_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5183,3 +5183,24 @@
"dgraph.type":["Friend1"],
"uid":"_:Friend1_1"
}
-
name: "Add mutation with language tag fields"
gqlmutation: |
mutation {
addPerson(input: { name: "Alice", nameHi: "ऐलिस",nameZh: "爱丽丝"}) {
person {
name
nameZh
nameHi
}
}
}
dgmutations:
- setjson: |
{ "Person.name":"Alice",
"Person.name@hi":"ऐलिस",
"Person.name@zh":"爱丽丝",
"dgraph.type": ["Person"],
"uid": "_:Person_1"
}
27 changes: 27 additions & 0 deletions graphql/resolve/query_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3303,6 +3303,33 @@
}
}
-
name: "query language tag fields with filter and order"
gqlquery: |
query {
queryPerson(filter:{or:[{name:{eq:"Alice"}},{nameHi:{eq:"ऐलिस"}},{nameZh:{eq:"爱丽丝"}},{name_Untag_AnyLang:{eq:"Alice"}}]}, order: { asc: nameHi })
{
name
nameZh
nameHi
nameHiZh
nameHi_Zh_Untag
name_Untag_AnyLang
}
}
dgquery: |-
query {
queryPerson(func: type(Person), orderasc: Person.name@hi) @filter((eq(Person.name, "Alice") OR eq(Person.name@hi, "ऐलिस") OR eq(Person.name@zh, "爱丽丝") OR eq(Person.name@., "Alice"))) {
Person.name : Person.name
Person.nameZh : Person.name@zh
Person.nameHi : Person.name@hi
Person.nameHiZh : Person.name@hi:zh
Person.nameHi_Zh_Untag : Person.name@hi:zh:.
Person.name_Untag_AnyLang : Person.name@.
dgraph.uid : uid
}
}
- name: "get query on interface with @id field having interface argument set"
gqlquery: |
query {
Expand Down
5 changes: 5 additions & 0 deletions graphql/resolve/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ type ThingTwo implements Thing {
type Person {
id: ID!
name: String @search(by: [hash])
nameHi: String @dgraph(pred:"Person.name@hi") @search(by: [hash])
nameZh: String @dgraph(pred:"Person.name@zh") @search(by: [hash])
nameHiZh: String @dgraph(pred:"Person.name@hi:zh")
nameHi_Zh_Untag: String @dgraph(pred:"Person.name@hi:zh:.")
name_Untag_AnyLang: String @dgraph(pred:"Person.name@.") @search(by: [hash])
friends: [Person] @hasInverse(field: friends)
}

Expand Down
Loading

0 comments on commit bf5afe5

Please sign in to comment.