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

Creates a unit test to reproduce bug caused by conflict between entity key and field alias #3035

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
118 changes: 118 additions & 0 deletions gateway-js/src/__tests__/executeQueryPlan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6868,6 +6868,124 @@ describe('executeQueryPlan', () => {
`);
});

it('handles @key leading to a conflict with a requested alias', async () => {
const s1 = {
name: 'S1',
typeDefs: gql`
type Query {
object: O
}

type O @key(fields: "id") {
id: ID!
legacyId: ID
a: String
}
`,
resolvers: {
Query: {
object() {
return { __typename: 'O', id: 'newId', legacyId: 'legacyId', a: 'a' };
},
},
},
};

const s2 = {
name: 'S2',
typeDefs: gql`
extend type O @key(fields: "id") {
id: ID!
a: String @external
b: String @requires(fields: "a")
}
`,
resolvers: {
O: {
__resolveReference(ref: { id: number }) {
return ref;
},
b(o: { a: string }) {
return `B: ${o.a}`;
},
},
},
};

const { serviceMap, schema, queryPlanner } = getFederatedTestingSchema([
s1,
s2,
]);

const operationWithoutJoin = parseOp(
`
query TestQuery {
object {
id: legacyId
legacyId
a
}
}
`,
schema,
);

const queryPlanWithoutJoin = buildPlan(operationWithoutJoin, queryPlanner);
const requestContext = buildRequestContext();

const responseWithoutJoin = await executePlan(
queryPlanWithoutJoin,
operationWithoutJoin,
requestContext,
schema,
serviceMap,
);
expect(responseWithoutJoin.data).toMatchInlineSnapshot(`
Object {
"object": Object {
"a": "a",
"id": "legacyId",
"legacyId": "legacyId",
},
}
`);

const operationWithJoin = parseOp(
`
query TestQuery {
object {
id: legacyId
legacyId
a
b
}
}
`,
schema,
);

const queryPlanWithJoin = buildPlan(operationWithJoin, queryPlanner);

const responseWithJoin = await executePlan(
queryPlanWithJoin,
operationWithJoin,
requestContext,
schema,
serviceMap,
);
// BUG: id is returned as 'newId' instead of being the legacyId
expect(responseWithJoin.data).toMatchInlineSnapshot(`
Object {
"object": Object {
"a": "a",
"b": "B: a",
"id": "legacyId",
"legacyId": "legacyId",
},
}
`);
})

it('handles field conflicting when type-exploding', async () => {
const s1 = {
name: 'S1',
Expand Down