You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!-- ROUTER-457 -->
This pull request documents the directives added in
#3074. These will be
released in the next federation version (v2.9), which is targeted for
the end of the month.
Both directives are inspired by the [IBM cost
specification](https://ibm.github.io/graphql-specs/cost-spec.html#sec-The-Cost-Directive).
So, most of the documentation parrots their specification.
---------
Co-authored-by: Edward Huang <edward.huang@apollographql.com>
Copy file name to clipboardExpand all lines: docs/source/federated-schemas/federated-directives.mdx
+211Lines changed: 211 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -982,3 +982,214 @@ The selection syntax for `@fromContext` used in its `ContextFieldValue` is simil
982
982
When the same contextual value is set in multiple places, the `ContextFieldValue` must resolve all types from each place into a single value that matches the parameter type.
983
983
984
984
For examples using `@context` and `@fromContext`, see [Using contexts to share data along type hierarchies](../entities/use-contexts).
The `@cost` directivedefinesacustomweightforaschema location. For GraphOS Router, it customizes the operation cost calculation of the [demand control feature](/router/executing-operations/demand-control/).
1001
+
1002
+
If `@cost` is not specified for a field, a default value is used:
1003
+
- Scalars and enums have default cost of 0
1004
+
- Composite input and output types have default cost of 1
1005
+
1006
+
Regardless of whether `@cost` is specified on a field, the field cost for that field also accounts for its arguments and selections.
1007
+
1008
+
#### Arguments
1009
+
1010
+
<table class="field-table">
1011
+
<thead>
1012
+
<tr>
1013
+
<th>Name /<br/>Type</th>
1014
+
<th>Description</th>
1015
+
</tr>
1016
+
</thead>
1017
+
1018
+
<tbody>
1019
+
1020
+
<tr>
1021
+
<td>
1022
+
1023
+
##### `weight`
1024
+
1025
+
`Int!`
1026
+
</td>
1027
+
<td>
1028
+
1029
+
**Required.** Assigns a custom weight for scoring the current field.
The `@listSize` directive is used to customize the cost calculation of the [demand control feature](/router/executing-operations/demand-control/) of GraphOS Router.
1050
+
1051
+
In the static analysis phase, the cost calculator does not know how many entities will be returned by each list field in a given query. By providing an estimated list size for a field with `@listSize`, the cost calculator can produce a more accurate estimate the cost during static analysis.
1052
+
1053
+
#### Configuring static list sizes
1054
+
1055
+
The simplest way to define a list size for a field is to use the `assumedSize` argument. This defines a static assumed maximum length for a given list field in the schema.
Inthisexample, the `items` fieldcanberequestedwithpagingparameters. Iftheclientsendsaquerywithmultipleslicingarguments, thescoringalgorithmwillusethemaximumvalueofallspecifiedslicingarguments. Thefollowingqueryisassumedtoreturntenitemsinthescoringalgorithm.
1080
+
1081
+
```graphql
1082
+
queryMultipleSlicingArgumentsQuery {
1083
+
items(first: 5, last: 10)
1084
+
}
1085
+
```
1086
+
1087
+
In some cases, you may want to enforce that only one slicing argument is used. For example, you may want to ensure that clients request either the first _n_ items or the last _n_ items, but not both. You can do this by setting `requireOneSlicingArgument` to `true`.
Withthisupdatedschema, sending the the above `MultipleSlicingArgumentsQuery` with its two slicing arguments to a graph would result in an error, as would sending a query with no slicing arguments.
1096
+
1097
+
#### Cursor support
1098
+
1099
+
Some pagination patterns include extra information along with the requested entities. For example, we may have some schema with a cursor type.
Copy file name to clipboardExpand all lines: docs/source/federation-versions.mdx
+74Lines changed: 74 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,80 @@ For a comprehensive changelog for Apollo Federation and its associated libraries
26
26
27
27
- If you maintain a [subgraph-compatible library](./building-supergraphs/compatible-subgraphs/), consult this article to stay current with recently added directives. All of these directive definitions are also listed in the [subgraph specification](./subgraph-spec/#subgraph-schema-additions).
0 commit comments