Commit 0ccfd93
authored
<!-- ROUTER-384 -->
# Overview
Implements two new directives for demand control, based on the [IBM Cost
Specification](https://ibm.github.io/graphql-specs/cost-spec.html).
```
directive @cost(weight: Int!) on
| ARGUMENT_DEFINITION
| ENUM
| FIELD_DEFINITION
| INPUT_FIELD_DEFINITION
| OBJECT
| SCALAR
directive @listsize(
assumedSize: Int,
slicingArguments: [String!],
sizedFields: [String!],
requireOneSlicingArgument: Boolean = true
) on FIELD_DEFINITION
```
The `@cost` directive allows users to specify a custom weight for
fields, enums, input objects, and arguments. The weight is used in the
demand control cost calculation, both for static estimates as well as
actual cost calculations.
The `@listSize` directive allows users to specify expected sizes of list
fields in their schema. This can be a static value set through
`assumedSize` or a dynamic value using `slicingArguments` to get the
value from some paging parameters.
## Differences from the spec
The main difference from the IBM spec is that we use an `Int!` for
weight argument of `@cost`. This allows the parser to enforce this is
parameterized with proper numeric values instead of finding out at
runtime that an invalid `String!` weight was passed.
## Caveats for shared fields
When `@cost` or `@listSize` are used on a `@shareable` field with
different values, the composed directive will use a merged value that
takes the maximum weight or assumed size, when applicable.
1 parent 6cf28f2 commit 0ccfd93
16 files changed
Lines changed: 841 additions & 17 deletions
File tree
- .changeset
- composition-js/src
- __tests__
- __snapshots__
- merging
- gateway-js/src/__tests__/gateway
- internals-js/src
- specs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
796 | 796 | | |
797 | 797 | | |
798 | 798 | | |
799 | | - | |
| 799 | + | |
800 | 800 | | |
801 | 801 | | |
802 | 802 | | |
| |||
926 | 926 | | |
927 | 927 | | |
928 | 928 | | |
929 | | - | |
930 | | - | |
| 929 | + | |
| 930 | + | |
931 | 931 | | |
932 | 932 | | |
933 | 933 | | |
| |||
0 commit comments