question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for Apollo Federation directives

See original GitHub issue

Hello!

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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
shellscapecommented, Dec 18, 2020

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?

1reaction
csilverscommented, Mar 24, 2020

(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.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Federation-specific GraphQL directives
Apollo Federation defines a collection of directives that you use in your subgraph schemas to enable certain features.
Read more >
Directives - Apollo GraphQL Docs
Configure GraphQL types, fields, and arguments. Looking for Apollo Federation directives? See Federation-specific GraphQL directives. A directive decorates part ...
Read more >
Advanced topics on federated entities - Apollo GraphQL Docs
This article describes complex behaviors of federated entities beyond those covered in entity basics. Advanced @key s. A single entity can have multiple ......
Read more >
Apollo Federation subgraph specification
All of these directives are shown in Subgraph schema additions. If supporting Federation 1, sdl must omit all automatically added definitions from Subgraph ......
Read more >
Setting up managed federation - Apollo GraphQL Docs
This article describes how to set up Apollo Studio for a graph that uses Apollo Federation. As with all changes, you should first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found