slicknode/graphql-query-complexity

Feature request: Federation support for directives

jjm340 opened this issue · 3 comments

I setup complexity calculations at the Gateway level using directive complexity and the default complexity was returned instead of using the values that are on the subgraphs. It looks like the simpleEstimator did work though as it returned a result that was relative to how much was going on in the query.

When I moved the directiveEstimator to the subgraph, it correctly returned the complexity however.

I can go into further detail if needed.

ivome commented

Sounds more like a problem with federation than this library. Are the directives added to the gateway schema? My guess is that's the problem. The schema on which the complexity is calculated needs to have the directives (the gateway probably makes the most sense).

There is no "gateway schema", the gateway is just a gateway that aggregates the schemas of its subgraphs so I end up having to include this library in every apollo instance for each subgraph. Its not the end of the world as it's easier to do, but would be nice if I could include this in the gateway and then use the directives in each subgraph without having to remember to add this lib and accompanying validation rule.

ivome commented

There is no "gateway schema", the gateway is just a gateway that aggregates the schemas of its subgraphs.

The result of that aggregation is a combined GraphQL schema. This is what I meant by gateway schema. If the query complexity validation is performed on this gateway schema, the directives need to be applied to the fields there. If the fields don't have the complexity directive, the directiveEstimator ignores the fields. So you'd have to find a way to get apollo gateway to add the custom directives from the subgraphs to the schema where the complexity validation is run.

I found this with a quick google: https://dev.to/mandiwise/using-custom-directives-with-apollo-federation-4o6p
Haven't tested it though.