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

Implement @cost and @listSize directives for demand control #3074

Merged
merged 14 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions .changeset/happy-bats-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@apollo/composition": minor
"@apollo/federation-internals": minor
---

Implements two new directives for defining custom costs for demand control. The `@cost` directive allows setting a custom weight to a particular field in the graph, overriding the default cost calculation. The `@listSize` directive gives the cost calculator information about how to estimate the size of lists returned by subgraphs. This can either be a static size or a value derived from input arguments, such as paging parameters.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`composing custom core directives custom tag directive works when federa
"schema
@link(url: \\"https://specs.apollo.dev/link/v1.0\\")
@link(url: \\"https://specs.apollo.dev/join/v0.3\\", for: EXECUTION)
@link(url: \\"https://specs.apollo.dev/tag/v0.3\\", as: \\"mytag\\")
@link(url: \\"https://specs.apollo.dev/tag/v0.3\\", import: [{name: \\"@tag\\", as: \\"@mytag\\"}])
@link(url: \\"https://custom.dev/tag/v1.0\\", import: [\\"@tag\\"])
{
query: Query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ describe('composing custom core directives', () => {
expect(errors(result)).toStrictEqual([
[
'DIRECTIVE_COMPOSITION_ERROR',
'Could not find matching directive definition for argument to @composeDirective "@fooz" in subgraph "subgraphA". Did you mean "@foo"?',
'Could not find matching directive definition for argument to @composeDirective "@fooz" in subgraph "subgraphA". Did you mean "@foo" or "@cost"?',
]
]);
});
Expand Down Expand Up @@ -926,8 +926,8 @@ describe('composing custom core directives', () => {
expectCoreFeature(schema, 'https://custom.dev/tag', '1.0', [{ name: '@tag' }]);
const feature = schema.coreFeatures?.getByIdentity('https://specs.apollo.dev/tag');
expect(feature?.url.toString()).toBe('https://specs.apollo.dev/tag/v0.3');
expect(feature?.imports).toEqual([]);
expect(feature?.nameInSchema).toEqual('mytag');
expect(feature?.imports).toEqual([{ name: '@tag', as: '@mytag' }]);
expect(feature?.nameInSchema).toEqual('tag');
expect(printSchema(schema)).toMatchSnapshot();
});

Expand Down
Loading