Skip to content

Commit

Permalink
Add some tests for #3134 and #3136
Browse files Browse the repository at this point in the history
  • Loading branch information
sachindshinde committed Sep 17, 2024
1 parent e7aeb9f commit f49b35f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions composition-js/src/__tests__/compose.demandControl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ describe('demand control directive composition', () => {
assertCompositionSuccess(result);
expect(result.hints).toEqual([]);

expect(result.schema.directive(`cost`)).toBeDefined();
expect(result.schema.directive(`listSize`)).toBeDefined();
expect(result.schema.directive(`cost__listSize`)).toBeUndefined();

const costDirectiveApplications = fieldWithCost(result)?.appliedDirectivesOf('cost');
expect(costDirectiveApplications?.toString()).toMatchString(`@cost(weight: 5)`);

Expand Down Expand Up @@ -773,5 +777,38 @@ describe('demand control directive extraction', () => {
}
`);
});

it('does not attempt to extract them to the subgraphs with similar spec URL', () => {
const subgraphA = {
name: 'subgraph-a',
typeDefs: asFed2SubgraphDocument(gql`
extend schema
@link(url: "https://specs.apollo.dev.foo.com/cost/v0.1")
@composeDirective(name: "@cost")
directive @cost(weight: Int!) on FIELD_DEFINITION
type Query {
a: Int @cost(weight: 1)
}
`)
};

const result = composeServices([subgraphA]);
assertCompositionSuccess(result);
const supergraph = Supergraph.build(result.supergraphSdl);

expect(supergraph.subgraphs().get(subgraphA.name)?.toString()).toMatchString(`
schema
${FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS}
{
query: Query
}
type Query {
a: Int
}
`);
});
});
});

0 comments on commit f49b35f

Please sign in to comment.