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.

[Feature Request] Apollo Federation Support

See original GitHub issue

Apollo Federation makes uses of some custom directives:

https://www.apollographql.com/docs/apollo-server/federation/federation-spec/

Version and Environment Details

Operation system: macOS

IDE name and version: IntelliJ IDEA Ultimate 2019.2

Plugin version: 2.2.0

Expected Behaviour

  1. The following directives should not produce errors:

    directive @external on FIELD_DEFINITION
    directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
    directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
    directive @key(fields: _FieldSet!) on OBJECT | INTERFACE
    directive @extends on OBJECT | INTERFACE
    

    (These directives must NOT be in the GraphQL file itself)

  2. An extend type TypeName should be allowed to exist without the base type, as the base type may be defined by another service

Actual Behaviour

  1. Error: Unknown directive "XXX"
  2. Error: The extension 'TypeName' type [@x:x] is missing its base underlying type

Steps to Reproduce / Link to Repo with Reproduction and Instructions

type InternalType @key(fields: "id") {
  id: ID!
  xyz: String!
  externalObject: ExternalType @requires(fields: "xyz") @provides(fields: "foo")
}

# In reality you need EITHER extend OR @extends
# depending on which server this schema is defined in
# (Apollo Server allows extend, graphql-java requires @extends)
extend type ExternalType @key(fields: "id") @extends {
  id: ID! @external
  foo: String! @external
  bar: String! @external
  baz: String!
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:31
  • Comments:6

github_iconTop GitHub Comments

10reactions
paulschwarzcommented, Nov 4, 2019

Looking at the examples of how to configure and extend the plugin (https://github.com/jimkyndemeyer/graphql-config-examples) perhaps a boilerplate example for Apollo Federation would help people get started.

6reactions
jimkyndemeyercommented, Oct 30, 2019

Hi Nihal.

Thanks for using the plugin.

Like you mention, these directives are custom, and the plugin only ships with the directives that are described in the GraphQL spec. This is intentional, as new GraphQL frameworks appear all the time. For this reason you have to declare framework directives yourself, and ensure that they’re picked up as part of schema discovery. You can look at an example at https://github.com/jimkyndemeyer/graphql-config-examples/tree/master/extend-client-fields-and-directives which shows how to work with the @client Apollo directive.

Extending non-existing types violates the GraphQL Spec https://graphql.github.io/graphql-spec/June2018/#sec-Object-Extensions validation “The named type must already be defined and must be an Object type.” As such, graphql-java which this plugin is based on works correctly, so I’m not sure how we would go about adding support for this. Potentially the validation needs to be configurable as it makes sense to enforce it for other use cases.

I noted one interesting comment in your code example:

# (Apollo Server allows extend, graphql-java requires @extends)

If you declared your directives as expected, and used @extends I believe the plugin would work as is.

Best regards, Jim

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduction to Apollo Federation - Apollo GraphQL Docs
Federation supports a free managed mode with Apollo GraphOS, which helps you ... clients can fetch data from all of your subgraphs with...
Read more >
Feature Request: Support Apollo Graphql Federation #492
We use hundreds of microservices, and a monolithic GraphQL server becomes an unacceptable development bottleneck and single point of failure, so it becomes ......
Read more >
Apollo Federation compatibility - Feature Requests
Apollo says: To be part of a federated graph, an implementing service must conform to the Apollo Federation specification, which exposes the ...
Read more >
Apollo Federation – GraphQL Yoga
Please note that Apollo Federation implementation doesn't support ... const { parse } = require('graphql') const { buildSubgraphSchema } ...
Read more >
Apollo Federation
Implementing services are now known as subgraphs. If you find an outdated use of "implementing service," please submit article feedback or a pull...
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