Add support for Apollo Federation directives
See original GitHub issueHello!
I have taken an interest in using this library in one of my projects which uses Apollo Federation as its architecture for handling micro services. When using simple schemas, and linting from the root where it is possible to reach all services, this library works splendidly.
Problems start to arise, however, when using Federation’s custom directives. These directives are vital to build schemas because one service’s schema can fully interact with other service’s schemas without a problem, as they are isolated from one another. For some directives there are workarounds, but there are some problems with others as they conflict with the way that simple schemas are done.
Before explaining the problem, lets define a example by defining two types, suppose we have a A type and a B type. There is a micro service for handling A , as well as another one for B. The B type is defined in its own micro service, we don’t really care about its fields, only the fact that it has a id. Now lets define the A type, while also updating B so that it supports the new aType field.
type A @key(fields: "id") {
id: ID!
field: string
}
extend type B @key(fields: "id") {
id: ID! @external
aType: A
}
We are modifying a schema that belongs to another service seamlessly. All of this is possible thanks to the @key and @external directives that Apollo Federation provides. Using the linter on the schema above, however, generates 2 errors:
- @key and @external directives are not defined.
- In the B schema: “Field “B.id” can only be defined once.”. As B’s ID was defined in its own service’s schema, the linter thinks this is a double definition of a field.
The former can be solved with some workarounds, creating ‘dummy’ definitions of these directives on another schema file, but not actually using them on the real code. The latter, however, is a little bit more complex. As we are dealing with Federation, we need to put the ID there again so that we can use it and use the @external directive to indicate that we are using the same ID, not defining a new one.
Suggestion It would be very good if this library had simple support to Apollo/Apollo Federation directives (currently there are only 5 different directives). As of right now, there is no way to completely lint a project with Apollo Federation, as the use of these directives is inevitable. This issue would be considered fixed if some kind of option was created to allow support for Apollo Federation, ideally understanding the directives and linting them accordingly.
How much work do you think this would take? If needed, I could take a crack at it but wouldn’t know where to start.
Cheers
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:11 (2 by maintainers)
I’d luuuuurv to use this but the lack of native support for federation directives is a game ender. Any chance this could get some traction?
(I take it back, it hasn’t been working cleanly for us at all. The problem is when a schema file references types defined in some other schema file.)