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

Bugfix: Complete field is always using the first field def instead of… #3457

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ export const typeDefs = gql`
me: User
}

type Department {
id: String
name: String
}

type PasswordAccount @key(fields: "email") {
email: String!
department: Department
}

type SMSAccount @key(fields: "number") {
number: String
department: Department
}

union AccountType = PasswordAccount | SMSAccount
Expand Down
51 changes: 51 additions & 0 deletions packages/apollo-gateway/src/__tests__/buildQueryPlan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,4 +790,55 @@ describe('buildQueryPlan', () => {
}
`);
});

describe(`for union types`, () => {
it(`include same type in a union with different fields`, () => {
const query = gql`
{
user(id: "2") {
account {
... on SMSAccount {
number
department {
id
}
}
... on PasswordAccount {
department {
name
}
email
}
}
}
}
`;
const queryPlan = buildQueryPlan(buildOperationContext(schema, query));
expect(queryPlan).toMatchInlineSnapshot(`
QueryPlan {
Fetch(service: "accounts") {
{
user(id: "2") {
account {
__typename
... on SMSAccount {
number
department {
id
}
}
... on PasswordAccount {
department {
name
}
email
}
}
}
}
},
}
`);
});
});
});
4 changes: 2 additions & 2 deletions packages/apollo-gateway/src/buildQueryPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ function splitFields(
parentType,
group,
path,
fieldsForResponseName,
fieldsForParentType,
),
);
} else {
Expand Down Expand Up @@ -446,7 +446,7 @@ function splitFields(
runtimeParentType,
group,
path,
fieldsForResponseName,
fieldsForParentType,
),
);
}
Expand Down