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

feat(Apollo): Add support for @provides and @requires directive. #7503

Merged
merged 18 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from 17 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
57 changes: 32 additions & 25 deletions graphql/e2e/common/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4981,11 +4981,12 @@ func addMutationWithDeepExtendedTypeObjects(t *testing.T) {
varMap1 := map[string]interface{}{
"missionId": "Mission1",
"astronautId": "Astronaut1",
"name": "Guss Garissom",
"des": "Apollo1",
}
addMissionParams := &GraphQLParams{
Query: `mutation addMission($missionId: String!, $astronautId: ID!, $des: String!) {
addMission(input: [{id: $missionId, designation: $des, crew: [{id: $astronautId}]}]) {
Query: `mutation addMission($missionId: String!, $astronautId: ID!, $name: String!, $des: String!) {
addMission(input: [{id: $missionId, designation: $des, crew: [{id: $astronautId, name: $name}]}]) {
mission{
id
crew {
Expand Down Expand Up @@ -5027,6 +5028,7 @@ func addMutationWithDeepExtendedTypeObjects(t *testing.T) {
varMap2 := map[string]interface{}{
"missionId": "Mission2",
"astronautId": "Astronaut1",
"name": "Gus Garrisom",
"des": "Apollo2",
}
addMissionParams.Variables = varMap2
Expand Down Expand Up @@ -5067,10 +5069,11 @@ func addMutationWithDeepExtendedTypeObjects(t *testing.T) {

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"}]}]) {
Query: `mutation addAstronaut($id1: ID!, $name1: String!, $missionId1: String!, $id2: ID!, $name2: String!, $missionId2: String! ) {
addAstronaut(input: [{id: $id1, name: $name1, missions: [{id: $missionId1, designation: "Apollo1"}]}, {id: $id2, name: $name2, missions: [{id: $missionId2, designation: "Apollo11"}]}]) {
astronaut(order: {asc: id}){
id
name
missions {
id
designation
Expand All @@ -5080,8 +5083,10 @@ func addMutationOnExtendedTypeWithIDasKeyField(t *testing.T) {
}`,
Variables: map[string]interface{}{
"id1": "Astronaut1",
"name1": "Gus Grissom",
"missionId1": "Mission1",
"id2": "Astronaut2",
"name2": "Neil Armstrong",
"missionId2": "Mission2",
},
}
Expand All @@ -5091,27 +5096,29 @@ func addMutationOnExtendedTypeWithIDasKeyField(t *testing.T) {

expectedJSON := `{
"addAstronaut": {
"astronaut": [
{
"id": "Astronaut1",
"missions": [
{
"id": "Mission1",
"designation": "Apollo1"
}
]
},
{
"id": "Astronaut2",
"missions": [
{
"id": "Mission2",
"designation": "Apollo2"
}
]
}
]
}
"astronaut": [
{
"id": "Astronaut1",
"name": "Gus Grissom",
"missions": [
{
"id": "Mission1",
"designation": "Apollo1"
}
]
},
{
"id": "Astronaut2",
"name": "Neil Armstrong",
"missions": [
{
"id": "Mission2",
"designation": "Apollo11"
}
]
}
]
}
}`

testutil.CompareJSON(t, expectedJSON, string(gqlResponse.Data))
Expand Down
3 changes: 2 additions & 1 deletion graphql/e2e/directives/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ type Section {

type Mission @key(fields: "id") {
id: String! @id
crew: [Astronaut] @hasInverse(field: missions)
crew: [Astronaut] @provides(fields: "name") @hasInverse(field: missions)
spaceShip: [SpaceShip]
designation: String!
startDate: String
Expand All @@ -318,6 +318,7 @@ type Mission @key(fields: "id") {

type Astronaut @key(fields: "id") @extends {
id: ID! @external
name: String @external
missions: [Mission]
}

Expand Down
4 changes: 4 additions & 0 deletions graphql/e2e/directives/schema_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"predicate": "author1.posts",
"type": "uid"
},
{
"predicate": "Astronaut.name",
"type": "string"
},
{
"predicate": "Astronaut.missions",
"type": "uid",
Expand Down
3 changes: 2 additions & 1 deletion graphql/e2e/normal/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ type Employer {

type Mission @key(fields: "id") {
id: String! @id
crew: [Astronaut] @hasInverse(field: missions)
crew: [Astronaut] @provides(fields: "name") @hasInverse(field: missions)
spaceShip: [SpaceShip]
designation: String!
startDate: String
Expand All @@ -336,6 +336,7 @@ type Mission @key(fields: "id") {

type Astronaut @key(fields: "id") @extends {
id: ID! @external
name: String! @external
missions: [Mission]
}

Expand Down
4 changes: 4 additions & 0 deletions graphql/e2e/normal/schema_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
],
"upsert": true
},
{
"predicate": "Astronaut.name",
"type": "string"
},
{
"predicate": "Astronaut.missions",
"type": "uid",
Expand Down
Loading