From 583cfe471fa2890907869ec098aad98dc7506825 Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Wed, 27 Jan 2021 13:08:13 +0530 Subject: [PATCH 1/4] fix e2e tests --- graphql/e2e/common/mutation.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/graphql/e2e/common/mutation.go b/graphql/e2e/common/mutation.go index 714c2701944..ec3fef2711e 100644 --- a/graphql/e2e/common/mutation.go +++ b/graphql/e2e/common/mutation.go @@ -4752,6 +4752,12 @@ func addMutationWithDeepExtendedTypeObjects(t *testing.T) { } }` testutil.CompareJSON(t, expectedJSON, string(gqlResponse1.Data)) + + astronautDeleteFilter := map[string]interface{}{"id": []string{"Astronaut1"}} + DeleteGqlType(t, "Astronaut", astronautDeleteFilter, 2, nil) + + missionDeleteFilter := map[string]interface{}{"id": map[string]interface{}{"in": []string{"Mission1", "Mission2"}}} + DeleteGqlType(t, "Mission", missionDeleteFilter, 2, nil) } func addMutationOnExtendedTypeWithIDasKeyField(t *testing.T) { @@ -4804,4 +4810,10 @@ func addMutationOnExtendedTypeWithIDasKeyField(t *testing.T) { }` testutil.CompareJSON(t, expectedJSON, string(gqlResponse.Data)) + + astronautDeleteFilter := map[string]interface{}{"id": []string{"Astronaut1", "Astronaut2"}} + DeleteGqlType(t, "Astronaut", astronautDeleteFilter, 2, nil) + + missionDeleteFilter := map[string]interface{}{"id": map[string]interface{}{"in": []string{"Mission1", "Mission2"}}} + DeleteGqlType(t, "Mission", missionDeleteFilter, 2, nil) } From 5f054420756ddb2ace3919b584179ab7164e38d5 Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Wed, 27 Jan 2021 14:39:43 +0530 Subject: [PATCH 2/4] fix build filter --- graphql/e2e/common/mutation.go | 7 +++++-- graphql/resolve/query_rewriter.go | 35 ++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/graphql/e2e/common/mutation.go b/graphql/e2e/common/mutation.go index ec3fef2711e..d59e67f1e18 100644 --- a/graphql/e2e/common/mutation.go +++ b/graphql/e2e/common/mutation.go @@ -4688,6 +4688,9 @@ func addMutationWithDeepExtendedTypeObjects(t *testing.T) { id crew { id + missions(order: {asc: id}){ + id + } } } } @@ -4754,7 +4757,7 @@ func addMutationWithDeepExtendedTypeObjects(t *testing.T) { testutil.CompareJSON(t, expectedJSON, string(gqlResponse1.Data)) astronautDeleteFilter := map[string]interface{}{"id": []string{"Astronaut1"}} - DeleteGqlType(t, "Astronaut", astronautDeleteFilter, 2, nil) + DeleteGqlType(t, "Astronaut", astronautDeleteFilter, 1, nil) missionDeleteFilter := map[string]interface{}{"id": map[string]interface{}{"in": []string{"Mission1", "Mission2"}}} DeleteGqlType(t, "Mission", missionDeleteFilter, 2, nil) @@ -4764,7 +4767,7 @@ func addMutationOnExtendedTypeWithIDasKeyField(t *testing.T) { addAstronautParams := &GraphQLParams{ Query: `mutation addAstronaut($id1: ID!, $missionId1: String!, $id2: ID!, $missionId2: String! ) { addAstronaut(input: [{id: $id1, missions: [{id: $missionId1, designation: "Apollo1"}]}, {id: $id2, missions: [{id: $missionId2, designation: "Apollo2"}]}]) { - astronaut{ + astronaut(order: {asc: id}){ id missions { id diff --git a/graphql/resolve/query_rewriter.go b/graphql/resolve/query_rewriter.go index 27034b57d9c..3bf7068f751 100644 --- a/graphql/resolve/query_rewriter.go +++ b/graphql/resolve/query_rewriter.go @@ -1826,14 +1826,33 @@ func buildFilter(typ schema.Type, filter map[string]interface{}) *gql.FilterTree }, }) case []interface{}: - // ids: [ 0x123, 0x124 ] -> uid(0x123, 0x124) - ids := convertIDs(dgFunc) - ands = append(ands, &gql.FilterTree{ - Func: &gql.Function{ - Name: "uid", - UID: ids, - }, - }) + // ids: [ 0x123, 0x124] + + // If ids is an @external field then it gets rewritten just like `in` filter + // ids: [0x123, 0x124] -> eq(typeName.ids, "0x123", 0x124) + if typ.Field(field).IsExternal() { + fn := "eq" + args := []gql.Arg{{Value: typ.DgraphPredicate(field)}} + for _, v := range dgFunc { + args = append(args, gql.Arg{Value: maybeQuoteArg(fn, v)}) + } + ands = append(ands, &gql.FilterTree{ + Func: &gql.Function{ + Name: fn, + Args: args, + }, + }) + } else { + // if it is not an @external field then it is rewritten as uid filter. + // ids: [ 0x123, 0x124 ] -> uid(0x123, 0x124) + ids := convertIDs(dgFunc) + ands = append(ands, &gql.FilterTree{ + Func: &gql.Function{ + Name: "uid", + UID: ids, + }, + }) + } case interface{}: // has: comments -> has(Post.comments) // OR From 4b47b5fd80affc5712f4e3c237a40537aaec4851 Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Wed, 27 Jan 2021 14:47:22 +0530 Subject: [PATCH 3/4] modify apolloservice result --- .../testdata/apolloservice/output/auth-directive.graphql | 4 ++++ .../testdata/apolloservice/output/custom-directive.graphql | 4 ++++ .../testdata/apolloservice/output/extended-types.graphql | 4 ++++ .../testdata/apolloservice/output/generate-directive.graphql | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/graphql/schema/testdata/apolloservice/output/auth-directive.graphql b/graphql/schema/testdata/apolloservice/output/auth-directive.graphql index 940e34aa1de..aeb264de8d2 100644 --- a/graphql/schema/testdata/apolloservice/output/auth-directive.graphql +++ b/graphql/schema/testdata/apolloservice/output/auth-directive.graphql @@ -202,6 +202,7 @@ directive @cacheControl(maxAge: Int!) on QUERY input IntFilter { eq: Int + in: [Int] le: Int lt: Int ge: Int @@ -211,6 +212,7 @@ input IntFilter { input Int64Filter { eq: Int64 + in: [Int64] le: Int64 lt: Int64 ge: Int64 @@ -220,6 +222,7 @@ input Int64Filter { input FloatFilter { eq: Float + in: [Float] le: Float lt: Float ge: Float @@ -229,6 +232,7 @@ input FloatFilter { input DateTimeFilter { eq: DateTime + in: [DateTime] le: DateTime lt: DateTime ge: DateTime diff --git a/graphql/schema/testdata/apolloservice/output/custom-directive.graphql b/graphql/schema/testdata/apolloservice/output/custom-directive.graphql index fb49e096dce..9d9423677d7 100644 --- a/graphql/schema/testdata/apolloservice/output/custom-directive.graphql +++ b/graphql/schema/testdata/apolloservice/output/custom-directive.graphql @@ -194,6 +194,7 @@ directive @cacheControl(maxAge: Int!) on QUERY input IntFilter { eq: Int + in: [Int] le: Int lt: Int ge: Int @@ -203,6 +204,7 @@ input IntFilter { input Int64Filter { eq: Int64 + in: [Int64] le: Int64 lt: Int64 ge: Int64 @@ -212,6 +214,7 @@ input Int64Filter { input FloatFilter { eq: Float + in: [Float] le: Float lt: Float ge: Float @@ -221,6 +224,7 @@ input FloatFilter { input DateTimeFilter { eq: DateTime + in: [DateTime] le: DateTime lt: DateTime ge: DateTime diff --git a/graphql/schema/testdata/apolloservice/output/extended-types.graphql b/graphql/schema/testdata/apolloservice/output/extended-types.graphql index ecd52019190..e740f1abacc 100644 --- a/graphql/schema/testdata/apolloservice/output/extended-types.graphql +++ b/graphql/schema/testdata/apolloservice/output/extended-types.graphql @@ -198,6 +198,7 @@ directive @cacheControl(maxAge: Int!) on QUERY input IntFilter { eq: Int + in: [Int] le: Int lt: Int ge: Int @@ -207,6 +208,7 @@ input IntFilter { input Int64Filter { eq: Int64 + in: [Int64] le: Int64 lt: Int64 ge: Int64 @@ -216,6 +218,7 @@ input Int64Filter { input FloatFilter { eq: Float + in: [Float] le: Float lt: Float ge: Float @@ -225,6 +228,7 @@ input FloatFilter { input DateTimeFilter { eq: DateTime + in: [DateTime] le: DateTime lt: DateTime ge: DateTime diff --git a/graphql/schema/testdata/apolloservice/output/generate-directive.graphql b/graphql/schema/testdata/apolloservice/output/generate-directive.graphql index c13862b61a9..3659d783e75 100644 --- a/graphql/schema/testdata/apolloservice/output/generate-directive.graphql +++ b/graphql/schema/testdata/apolloservice/output/generate-directive.graphql @@ -204,6 +204,7 @@ directive @cacheControl(maxAge: Int!) on QUERY input IntFilter { eq: Int + in: [Int] le: Int lt: Int ge: Int @@ -213,6 +214,7 @@ input IntFilter { input Int64Filter { eq: Int64 + in: [Int64] le: Int64 lt: Int64 ge: Int64 @@ -222,6 +224,7 @@ input Int64Filter { input FloatFilter { eq: Float + in: [Float] le: Float lt: Float ge: Float @@ -231,6 +234,7 @@ input FloatFilter { input DateTimeFilter { eq: DateTime + in: [DateTime] le: DateTime lt: DateTime ge: DateTime From 90947dc4485dbae55447eb0ab5ab45fe17ebf92c Mon Sep 17 00:00:00 2001 From: minhaj-shakeel Date: Wed, 27 Jan 2021 14:57:51 +0530 Subject: [PATCH 4/4] modify entities query --- graphql/e2e/common/query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphql/e2e/common/query.go b/graphql/e2e/common/query.go index 3275c4cdd04..ddc5ce4b123 100644 --- a/graphql/e2e/common/query.go +++ b/graphql/e2e/common/query.go @@ -403,7 +403,7 @@ func entitiesQuery(t *testing.T) { Query: `query _entities($typeName: String!, $id1: String!, $id2: String!){ _entities(representations: [{__typename: $typeName, id: $id1}, {__typename: $typeName, id: $id2 }]) { ... on SpaceShip { - missions { + missions(order: {asc: id}){ id designation }