Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Apollo federation): code refractor #7366

Merged
merged 4 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion graphql/e2e/common/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4688,6 +4688,9 @@ func addMutationWithDeepExtendedTypeObjects(t *testing.T) {
id
crew {
id
missions(order: {asc: id}){
id
}
}
}
}
Expand Down Expand Up @@ -4752,13 +4755,19 @@ func addMutationWithDeepExtendedTypeObjects(t *testing.T) {
}
}`
testutil.CompareJSON(t, expectedJSON, string(gqlResponse1.Data))

astronautDeleteFilter := map[string]interface{}{"id": []string{"Astronaut1"}}
DeleteGqlType(t, "Astronaut", astronautDeleteFilter, 1, nil)

missionDeleteFilter := map[string]interface{}{"id": map[string]interface{}{"in": []string{"Mission1", "Mission2"}}}
DeleteGqlType(t, "Mission", missionDeleteFilter, 2, nil)
}

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
Expand Down Expand Up @@ -4804,4 +4813,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)
}
2 changes: 1 addition & 1 deletion graphql/e2e/common/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
35 changes: 27 additions & 8 deletions graphql/resolve/query_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ directive @cacheControl(maxAge: Int!) on QUERY

input IntFilter {
eq: Int
in: [Int]
le: Int
lt: Int
ge: Int
Expand All @@ -211,6 +212,7 @@ input IntFilter {

input Int64Filter {
eq: Int64
in: [Int64]
le: Int64
lt: Int64
ge: Int64
Expand All @@ -220,6 +222,7 @@ input Int64Filter {

input FloatFilter {
eq: Float
in: [Float]
le: Float
lt: Float
ge: Float
Expand All @@ -229,6 +232,7 @@ input FloatFilter {

input DateTimeFilter {
eq: DateTime
in: [DateTime]
le: DateTime
lt: DateTime
ge: DateTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ directive @cacheControl(maxAge: Int!) on QUERY

input IntFilter {
eq: Int
in: [Int]
le: Int
lt: Int
ge: Int
Expand All @@ -203,6 +204,7 @@ input IntFilter {

input Int64Filter {
eq: Int64
in: [Int64]
le: Int64
lt: Int64
ge: Int64
Expand All @@ -212,6 +214,7 @@ input Int64Filter {

input FloatFilter {
eq: Float
in: [Float]
le: Float
lt: Float
ge: Float
Expand All @@ -221,6 +224,7 @@ input FloatFilter {

input DateTimeFilter {
eq: DateTime
in: [DateTime]
le: DateTime
lt: DateTime
ge: DateTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ directive @cacheControl(maxAge: Int!) on QUERY

input IntFilter {
eq: Int
in: [Int]
le: Int
lt: Int
ge: Int
Expand All @@ -207,6 +208,7 @@ input IntFilter {

input Int64Filter {
eq: Int64
in: [Int64]
le: Int64
lt: Int64
ge: Int64
Expand All @@ -216,6 +218,7 @@ input Int64Filter {

input FloatFilter {
eq: Float
in: [Float]
le: Float
lt: Float
ge: Float
Expand All @@ -225,6 +228,7 @@ input FloatFilter {

input DateTimeFilter {
eq: DateTime
in: [DateTime]
le: DateTime
lt: DateTime
ge: DateTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ directive @cacheControl(maxAge: Int!) on QUERY

input IntFilter {
eq: Int
in: [Int]
le: Int
lt: Int
ge: Int
Expand All @@ -213,6 +214,7 @@ input IntFilter {

input Int64Filter {
eq: Int64
in: [Int64]
le: Int64
lt: Int64
ge: Int64
Expand All @@ -222,6 +224,7 @@ input Int64Filter {

input FloatFilter {
eq: Float
in: [Float]
le: Float
lt: Float
ge: Float
Expand All @@ -231,6 +234,7 @@ input FloatFilter {

input DateTimeFilter {
eq: DateTime
in: [DateTime]
le: DateTime
lt: DateTime
ge: DateTime
Expand Down