federation icon indicating copy to clipboard operation
federation copied to clipboard

Deliver: Compose user directives

Open clenfest opened this issue 3 years ago • 2 comments

We'd like to compose user directives in a standard way that mirrors what we've done in toAPISchema.

In general there are two cases we need to handle, executable directives which apply to queries and type system directives which apply to type system locations.

The rule for each is:

  1. all executable directives are (potentially) merged, but they are merged by "intersection" across subgraphs and that means that a given definition may not "make it" in the supergraph if definitions are too inconsistent between subgraphs. Because we don't know when the directive will be used in queries, we need to restrict the definition so that no query will be forced to deal with a directive it doesn't understand.
  2. For type system directives, it is safe to merge the locations by union since we know that any references to the directive will originate from the subgraphs themselves, and and a broader definition is not problematic.

If a directive definition has both type system and executable locations, composition will ignore the type system locations and merge the directive as an executable one, with only its executable locations

The default behavior should be to not compose user directives unless requested to during composition. Let's add an exposeDirectives argument to compose which takes a list of custom directives (we need to be able to support both core schema and regular directives). If a directive is present in the list, it will appear in the supergraph, otherwise not. Also, ensure that all directives specified as an argument are present in the schema of at least one subgraph to mitigate directive name typos.

There is probably work to be done in field merging as well to ensure that directives that are repeatable will get values from all subgraphs, and values that are not repeatable deterministically select a sane choice from one of the subgraphs.

clenfest avatar May 26 '22 14:05 clenfest

Hey @clenfest, I'm more than happy to hack and help with this one since we also need this functionality.

Please, let me know if there's anything I can do.

romanschejbal avatar Jun 01 '22 12:06 romanschejbal

Hi @romanschejbal. Thanks for the offer, I've got a draft PR up that we'll kick around, but we're moving on this one.

clenfest avatar Jun 01 '22 22:06 clenfest

Closing out this issue as it was released earlier this week.

jeffjakub avatar Aug 31 '22 14:08 jeffjakub