Skip to content

Commit

Permalink
Bugfix: Complete field is always using the first field def instead of…
Browse files Browse the repository at this point in the history
… the current one
  • Loading branch information
Tejas Shikhare committed Oct 29, 2019
1 parent 05d5370 commit f2cc553
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
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
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
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

0 comments on commit f2cc553

Please sign in to comment.