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.

Allow for multiple remote endpoints

See original GitHub issue

One of things things that has me a little confused, is the seemingly lack of versioning recommended by GraphQL implementation articles and examples. Speaking for our team, we are already planning on making our current implementation essentially a pre release (/graphql) and starting with our apollo server build out at api/v1 or graphql/v1.

That being said, I’m interested to get thoughts on using the apollo client with multiple remote endpoints. Here are a few examples / thoughts on the api design

3rd party service + in house service

Let’s say we look into the future a year or so. GraphQL has solidified around a standard (already pretty dang close!) and more and more services offer Graph endpoints along with their standard REST endpoints. So I’m building an app that pulls from my app source, and pulls from reddit for example.

// a vanilla, not external redux store example
import ApolloClient, { createNetworkInterface } from "apollo-client";

const Reddit = createNetworkInterface('https://reddit.com/graphql');
const Heighliner = createNetworkInterface('https://api.newspring.cc/graphql');

// we can either specify the remote locations on the queries
// fwiw, I think this is a bad idea ;) but anything is possible right?
// this would mean only on client instantiated with multiple network interfaces passed to it
`
  @Reddit
  query getCategory($categoryId: Int!) {
      category(id: $categoryId) {
        name
        color
      }
    }
`

`
  @Heighliner
  query getCategory($categoryId: Int!) {
      category(id: $categoryId) {
        name
        color
      }
    }
`

const client = new ApolloClient({
  networkInterface: {
    Reddit,
    Heighliner
  }
})

// or we can create multiple clients but will have to figure out the duplicate store key
const RedditClient = new ApolloClient({
  networkInterface: Reddit,
  reduxRootKey: "reddit",
});

const HeighlinerClient = new ApolloClient({
  networkInterface: Heighliner,
  reduxRootKey: "heighliner",
});

Personally I am a fan of instantiating multiple clients as the two endpoints should have no overlap (if they did, your GraphQL server should be handling the linking, not the client). That also gives us the benefit of doing something like this in the future

Remote service + local service. One query / action language to rule them all

// a vanilla, not external redux store example
import ApolloClient, { createNetworkInterface, createLocalInterface } from "apollo-client";

// localGraphQLResolver is a client side implementation of a graphql app
// it allows for mutations to update / change local state of the app
// and queries to get app state
// @NOTE this is just an idea I've been playing with. Hope to have an example soon
const Local = createLocalInterface(localGraphQLResolver); 
const Heighliner = createNetworkInterface('https://api.newspring.cc/graphql');

const App = new ApolloClient({
  networkInterface: Local,
  reduxRootKey: "local",
});

const HeighlinerClient = new ApolloClient({
  networkInterface: Heighliner,
  reduxRootKey: "heighliner",
});

So all in all, I don’t think this requires any API changes, just wanted to bring it up 👍

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:50 (17 by maintainers)

github_iconTop GitHub Comments

51reactions
stubailocommented, Apr 9, 2016

Personally, I think the main strength of GraphQL is having exactly one endpoint. If you’re querying multiple GraphQL servers from the same client, I feel like you’re doing it wrong (just my opinion at the moment).

I think having a function in the server to proxy part of the schema to a different GraphQL server would be the right approach, so that you maintain the property that you can render your whole UI with one roundtrip.

As for merging client and server data, I have a few ideas for how to do that, but I think that’s a special case - it should be exactly one server schema and one client schema IMO.

One main argument for me is that the whole point of GraphQL is to be able to traverse data in the same query, and have schema types that reference each other - just sending two root queries to different servers doesn’t really give you any benefit over just initializing two clients IMO.

We have some ideas for how this might work in a future Apollo proxy server, which would let you traverse between schemas at will in a single query, from your schema, to external services, etc.

19reactions
ffxsamcommented, May 23, 2017

@stubailo I just thought of this and stumbled upon this issue. I saw GitHub released a GraphQL API, and thought “how would I write a front-end app that connected to my own GraphQL backend, but also used GitHub’s API?” I don’t know of any way for Apollo to connect to multiple servers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to configure multiple remote sessions to same endpoint ...
How to configure multiple remote sessions to same endpoint in Remote Control · Log into ITarian · Click 'Applications' > 'Endpoint Manager' ·...
Read more >
How to configure multiple remote sessions to ... - Wiki Comodo
How to configure multiple remote sessions to same endpoint in Remote Control · Log into Comodo One / Dragon · Click 'Applications' >...
Read more >
HowTo: Enable multiple sessions for Remote Desktop Services
Enable Multiple RDP Sessions​​ Open the start screen (press the Windows key) and type gpedit. msc and open it.
Read more >
Remote Access VPN with Multiple Endpoints - Cisco Community
We are looking for a solution wherein the users only needs to login into a single endpoint then that endpoint routes or decides...
Read more >
Remote Access Best Practices for 2021 | NinjaOne
Multi -monitor support allowing one technician to access multiple endpoints. · Multiple sessions · Connection security · Collaborative access ...
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