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.

Support local and remote services in ApolloGateway

See original GitHub issue

Currently ApolloGateway supports the serviceList option for remote GraphQL services and localServiceList for local GraphQL schemas, but they cannot be used together. It would be great if ApolloGateway allowed both remote and local schemas.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
tjwallacecommented, Sep 9, 2019

Sorry I should have mentioned that I had tried returning a LocalGraphQLDataSource inside of buildService but ran into some issues:

  1. This check requires a url in the service definition.
  2. This object eventually gets passed to buildService (a second time for the service), but does not include anything originally in the definition (like schema) so I have to do a check on name and then reference schema from a higher scope. Is this expected? I didn’t originally notice this so now I have it working.

Here is what I have now for reference. Is this the “correct” way to use LocalGraphQLDataSource?

// local schema
const schema = buildFederatedSchema([Foo, Bar, Baz]);

const serviceList = [
  // can't add `schema` to this object because `buildService()` will eventually be
  // called a second time without it (only name, url and typeDefs)
  { name: 'local', url: 'local' },
  { name: 'remote', url: 'http://remote.com/graphql' }
];

const gateway = new ApolloGateway({
  serviceList,
  buildService({ name, url }) {
    if (name === 'local') {
      return new LocalGraphQLDataSource(schema);
    }

    return new RemoteGraphQLDataSource({ url });
  }
});
0reactions
mac2000commented, Dec 15, 2020

@rahul22048 oh it is very old at very end we did make following:

right inside apollo federation gateway wrap all services with code pieces from graphql federation transformation

in at very end our gateway was something like:

var gateway = new Gateway({ services: process([
    {name: 'federated-service-1', url: 'http://localhost:3000'},
    {name: 'nonfederated-service-2', url: 'http://localhost:5000', config: require('./nonfederated-service-2.js')},
]) })

where process function inside returned records as is if there were no config property, other wise do transformation with applied configs

and it was working for a while, but later we did manage how to make federation support in dotnet so no need for this, at moment everything is working without any proxies

Read more comments on GitHub >

github_iconTop Results From Across the Web

API Reference: @apollo/gateway - Apollo GraphQL Docs
This API reference documents the exports from the @apollo/gateway package. This package enables you to use ... url: 'https://products-service.dev/graphql',.
Read more >
graphql - Is it possible to have partially federated gateway?
Now it looks like I need to have federation gateway service, federated graphql service(s) and the rest<->graphql bridge service separately.
Read more >
Support GraphQL schema federation - DatoCMS community
Hi, Is it possible to use Apollo Federation with remote schemas which is generated by third-party service? I want to merge my API...
Read more >
Apollo Federation with local schemas - koala-moon
KEY || ''; // This string is uses to access the remote services inside or micro service environment. It is used once when...
Read more >
Implementing Federated GraphQL Microservices using Apollo ...
Each service is responsible for resolving only the part of the data graph that includes ... npm i --save apollo-server @apollo/federation @apollo/gateway ......
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