kbrandwijk / graphcool-gateway-examples

A collection of examples using the API Gateway pattern with Apollo Schema Stitching
GNU General Public License v3.0
5 stars 0 forks source link

Example ideas #1

Open kbrandwijk opened 6 years ago

kbrandwijk commented 6 years ago

Ideas welcome!

antho1404 commented 6 years ago

If I can add something, I have a saas product (not on graphcool) and I was thinking how I could migrate it because I'm using multi-tenancy with postgres and I think gateway could be a way to do that with different project and the gateway redirect to one api or the other. I don't know if that make sense to use gateways like that

kbrandwijk commented 6 years ago

@antho1404 Can you explain a bit more about your set up? From what I understand, you now have a multi-tenancy setup, and you are thinking of creating a seperate service for each tenant, and redirect to the right service in the API Gateway? In that case, the Gateway would just do the routing, and I don't think you need to setup the Gateway as a graphql endpoint, but a 'proxy' solution would also work.

You could simply use something like https://www.npmjs.com/package/express-http-proxy, and use a method to determine where to route:

function getHost() { 
  // determine endpoint based on authorization header
  return `https://api.graph.cool/simple/v1/${tenantServiceId}`
}

app.use('/graphql', proxy(getHost, {
  memoizeHost: false
}))
antho1404 commented 6 years ago

You exactly get the idea, and yes the proxy will definitely do the job, I just see the gateway as a proxy but I guess it can be more that this, I will try to take time to look more about what's the real benefits with the gateway