Skip to content

Commit

Permalink
fix(Apollo): fix tests (#7372)
Browse files Browse the repository at this point in the history
  • Loading branch information
minhaj-shakeel authored Jan 27, 2021
1 parent 30d4934 commit 06bee5c
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 10 deletions.
166 changes: 165 additions & 1 deletion graphql/e2e/schema/apollo_service_response.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type Mission {

type Astronaut @key(fields: "id") @extends {
id: ID! @external
missions: [Mission]
missions(filter: MissionFilter, order: MissionOrder, first: Int, offset: Int): [Mission]
missionsAggregate(filter: MissionFilter): MissionAggregateResult
}

type User @remote {
Expand Down Expand Up @@ -207,6 +208,7 @@ directive @cacheControl(maxAge: Int!) on QUERY

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

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

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

input DateTimeFilter {
eq: DateTime
in: [DateTime]
le: DateTime
lt: DateTime
ge: DateTime
Expand Down Expand Up @@ -274,12 +279,51 @@ input StringHashFilter {
# Generated Types
#######################

type AddAstronautPayload {
astronaut(filter: AstronautFilter, order: AstronautOrder, first: Int, offset: Int): [Astronaut]
numUids: Int
}

type AddCarPayload {
car(filter: CarFilter, order: CarOrder, first: Int, offset: Int): [Car]
numUids: Int
}

type AddMissionPayload {
mission(filter: MissionFilter, order: MissionOrder, first: Int, offset: Int): [Mission]
numUids: Int
}

type AstronautAggregateResult {
count: Int
idMin: ID
idMax: ID
}

type CarAggregateResult {
count: Int
nameMin: String
nameMax: String
}

type DeleteAstronautPayload {
astronaut(filter: AstronautFilter, order: AstronautOrder, first: Int, offset: Int): [Astronaut]
msg: String
numUids: Int
}

type DeleteCarPayload {
car(filter: CarFilter, order: CarOrder, first: Int, offset: Int): [Car]
msg: String
numUids: Int
}

type DeleteMissionPayload {
mission(filter: MissionFilter, order: MissionOrder, first: Int, offset: Int): [Mission]
msg: String
numUids: Int
}

type MissionAggregateResult {
count: Int
designationMin: String
Expand All @@ -290,10 +334,33 @@ type MissionAggregateResult {
endDateMax: String
}

type UpdateAstronautPayload {
astronaut(filter: AstronautFilter, order: AstronautOrder, first: Int, offset: Int): [Astronaut]
numUids: Int
}

type UpdateCarPayload {
car(filter: CarFilter, order: CarOrder, first: Int, offset: Int): [Car]
numUids: Int
}

type UpdateMissionPayload {
mission(filter: MissionFilter, order: MissionOrder, first: Int, offset: Int): [Mission]
numUids: Int
}

#######################
# Generated Enums
#######################

enum AstronautHasFilter {
missions
}

enum AstronautOrderable {
id
}

enum CarHasFilter {
name
}
Expand All @@ -319,6 +386,45 @@ enum MissionOrderable {
# Generated Inputs
#######################

input AddAstronautInput {
id: ID!
missions: [MissionRef]
}

input AddCarInput {
name: String!
}

input AddMissionInput {
crew: [AstronautRef]
designation: String!
startDate: String
endDate: String
}

input AstronautFilter {
id: [ID!]
has: AstronautHasFilter
and: [AstronautFilter]
or: [AstronautFilter]
not: AstronautFilter
}

input AstronautOrder {
asc: AstronautOrderable
desc: AstronautOrderable
then: AstronautOrder
}

input AstronautPatch {
missions: [MissionRef]
}

input AstronautRef {
id: ID
missions: [MissionRef]
}

input CarFilter {
id: [ID!]
has: CarHasFilter
Expand All @@ -333,6 +439,15 @@ input CarOrder {
then: CarOrder
}

input CarPatch {
name: String
}

input CarRef {
id: ID
name: String
}

input MissionFilter {
id: [ID!]
has: MissionHasFilter
Expand All @@ -347,6 +462,39 @@ input MissionOrder {
then: MissionOrder
}

input MissionPatch {
crew: [AstronautRef]
designation: String
startDate: String
endDate: String
}

input MissionRef {
id: ID
crew: [AstronautRef]
designation: String
startDate: String
endDate: String
}

input UpdateAstronautInput {
filter: AstronautFilter!
set: AstronautPatch
remove: AstronautPatch
}

input UpdateCarInput {
filter: CarFilter!
set: CarPatch
remove: CarPatch
}

input UpdateMissionInput {
filter: MissionFilter!
set: MissionPatch
remove: MissionPatch
}

#######################
# Generated Query
#######################
Expand All @@ -361,3 +509,19 @@ type Query {
aggregateCar(filter: CarFilter): CarAggregateResult
}

#######################
# Generated Mutations
#######################

type Mutation {
addMission(input: [AddMissionInput!]!): AddMissionPayload
updateMission(input: UpdateMissionInput!): UpdateMissionPayload
deleteMission(filter: MissionFilter!): DeleteMissionPayload
addAstronaut(input: [AddAstronautInput!]!): AddAstronautPayload
updateAstronaut(input: UpdateAstronautInput!): UpdateAstronautPayload
deleteAstronaut(filter: AstronautFilter!): DeleteAstronautPayload
addCar(input: [AddCarInput!]!): AddCarPayload
updateCar(input: UpdateCarInput!): UpdateCarPayload
deleteCar(filter: CarFilter!): DeleteCarPayload
}

4 changes: 2 additions & 2 deletions graphql/resolve/auth_query_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,7 @@
dgraph.uid : uid
}
_EntityRoot as var(func: uid(Astronaut4))
Astronaut4 as var(func: uid(0x1, 0x2, 0x3)) @filter(type(Astronaut))
Astronaut4 as var(func: eq(Astronaut.id, "0x1", "0x2", "0x3")) @filter(type(Astronaut))
var(func: uid(_EntityRoot)) {
Mission2 as Astronaut.missions
}
Expand Down Expand Up @@ -1937,6 +1937,6 @@
dgraph.uid : uid
}
_EntityRoot as var(func: uid(Astronaut3))
Astronaut3 as var(func: uid(0x1, 0x2, 0x3)) @filter(type(Astronaut))
Astronaut3 as var(func: eq(Astronaut.id, "0x1", "0x2", "0x3")) @filter(type(Astronaut))
}
9 changes: 4 additions & 5 deletions graphql/resolve/query_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,6 @@
gqlquery: |
query {
getComment(id: "0x1") {
id
author
title
content
Expand All @@ -2487,10 +2486,10 @@
dgquery: |-
query {
getComment(func: uid(0x1)) @filter(type(Comment)) {
id : uid
author : Comment.author
title : Comment.title
ups : Comment.ups
id : uid
url : Comment.url
}
}
Expand Down Expand Up @@ -3211,9 +3210,9 @@
}
dgquery: |-
query {
_entities(func: uid(0x1, 0x2)) @filter(type(Astronaut)) {
_entities(func: eq(Astronaut.id, "0x1", "0x2")) @filter(type(Astronaut)) {
dgraph.type
Astronaut.missions : Astronaut.missions {
missions : Astronaut.missions {
designation : Mission.designation
dgraph.uid : uid
}
Expand All @@ -3237,7 +3236,7 @@
query {
_entities(func: eq(SpaceShip.id, "0x1", "0x2")) @filter(type(SpaceShip)) {
dgraph.type
SpaceShip.missions : SpaceShip.missions {
missions : SpaceShip.missions {
designation : Mission.designation
dgraph.uid : uid
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ directive @generate(

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

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

input FloatFilter {
eq: Float
in: [Float]
le: Float
lt: Float
ge: Float
Expand All @@ -258,6 +261,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 @@ -330,7 +330,7 @@ input StudentPatch {

input StudentRef {
regNo: ID
rollNo: String @id
rollNo: String
}

input UpdateStudentInput {
Expand Down
6 changes: 5 additions & 1 deletion graphql/schema/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func repeatedFieldMappings(s *ast.Schema, dgPreds map[string]map[string]string)
repeatedFieldNames := make(map[string]bool)

for _, typ := range s.Types {
if !isAbstractKind(typ.Kind) {
if !isAbstractKind(typ.Kind) || isEntityUnion(typ) {
continue
}

Expand Down Expand Up @@ -724,6 +724,10 @@ func hasExternal(f *ast.FieldDefinition) bool {
return f.Directives.ForName(apolloExternalDirective) != nil
}

func isEntityUnion(typ *ast.Definition) bool {
return typ.Kind == ast.Union && typ.Name == "_Entity"
}

func (f *field) IsExternal() bool {
return hasExternal(f.field.Definition)
}
Expand Down

0 comments on commit 06bee5c

Please sign in to comment.