Skip to content

Commit

Permalink
chore(@OverRide): add e2e testing of progressive overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
metrue committed Apr 11, 2024
1 parent 4e5f79d commit d61092c
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions gateway-js/src/__tests__/gateway/endToEnd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,94 @@ describe('caching', () => {
* have basic end-to-end testing, thus ensuring those feature don't break in places we didn't expect.
*/
describe('end-to-end features', () => {
it.only('@override progressive override', async () => {
const subgraphA = {
name: 'A',
url: 'https://A',
typeDefs: gql`
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.7"
import: ["@key", "@override"]
)
type Query {
t: T
}
type T @key(fields: "k") {
k: ID
x: Int
}
`,
resolvers: {
Query: {
t: () => ({
k: 42,
x: 1,
}),
},
},
};

const subgraphB = {
name: 'B',
url: 'https://B',
typeDefs: gql`
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.7"
import: ["@key", "@override"],
)
type T @key(fields: "k") {
k: ID
x: Int @override(from: "A", label: "percent(100)")
}
`,
resolvers: {
T: {
__resolveReference: ({ k }: { k: string }) => {
return k === '42' ? { x: 2 } : undefined;
},
},
},
};

services = await startSubgraphsAndGateway([subgraphA, subgraphB]);
const limit = 1000
const query = `
{
t {
k
x
}
}
`;
let hitsA = 0
let hitsB = 0
for (let i = 0; i < limit; i++) {
const response = await services.queryGateway(query);
const result = await response.json();
if (result.data.t.x === 1) {
hitsA++
}
if (result.data.t.x === 2) {
hitsB++
}
}
expect(hitsB).toEqual(1000);
expect(hitsA).toEqual(0);

const supergraphSdl = services.gateway.__testing().supergraphSdl;
expect(supergraphSdl).toBeDefined();
const supergraph = buildSchema(supergraphSdl!);
const typeT = supergraph.type('T') as ObjectType;
expect(
typeT.field('x')?.appliedDirectivesOf('@override').toString(),
).toStrictEqual('');
})

it('@tag renaming', async () => {
const subgraphA = {
name: 'A',
Expand Down

0 comments on commit d61092c

Please sign in to comment.