When calculating query complexity it feels like it ought to be the responsibility of the subgraph to declare the relative costs of the types and queries in its schema. Existing libraries such as graphql-cost-analysis allow you to do this via schema directives (e.g.
@cost) that can be applied to those elements.
It also seems clear that the ultimate arbiter as to whether a given query is “too complex” ought to be the gateway, given that the supplied query could be broken down into a number of smaller subgraph queries, the individual complexities of which should contribute to the overall score.
However the Apollo v2 federation docs explicitly state:
Custom directives are not included in your graph’s composed supergraph schema. The composition process strips all subgraph directives. Only a given subgraph is aware of its own directives.
Which appears to make it impossible to specify costing metadata at the subgraph level, but allow the gateway itself to police the incoming queries. The only approach which currently works would be to have individual subgraphs police the queries issued to them by the gateway, with no means of imposing restrictions on the total cost to the aggregated system,
Is this assumption correct, and if so are there any plans in federation to address this?