title: ECONNREFUSED when using apollo client to do graphQL query from getInitialProps method in nextjs
body: <p>Following the <a href="https://github.com/zeit/next.js/tree/canary/examples/with-apollo-auth" rel="nofollow noreferrer">with-apollo-auth</a> example
  Successful behavior when I do client-side ApolloConsumer query. I pass the client through and query works.</p>
  
  <p>Unsuccessful behavior when I attempt to do a server side query through getInitialProps. I pass the client through a handler that calls the same query and I get a ECONN refused error as shown below.</p>
  
  <p><a href="https://i.stack.imgur.com/KH2cH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KH2cH.png" alt="enter image description here"></a></p>
  
  <p><strong>Steps to reproduce the behavior:</strong></p>
  
  <p>I set up my ApolloClient in the init-apollo file as follows:</p>
  
  <pre><code>  const httpLink = createHttpLink({
      uri: 'http://localhost:8080/api/graphql',
      credentials: 'same-origin'
    })
  
    const authLink = setContext((_, { headers }) =&gt; {
      const token = getToken()
      return {
        headers: {
          ...headers,
          authorization: token ? `Bearer ${token}` : ''
        }
      }
    })
  
    return new ApolloClient({
      connectToDevTools: process.browser,
      ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
      link: ApolloLink.from([ authLink, httpLink ]),
      cache: new InMemoryCache().restore(initialState || {})
    })
  </code></pre>
  
  <p>I set up my query as follows:</p>
  
  <pre><code>import gql from 'graphql-tag'
  
  export default apolloClient =&gt; {
    apolloClient
      .query({
        query: gql`
          {
            getUser {
              id
            }
          }
        `
      })
      .then(({data}) =&gt; {
        console.log(data);
        return { userDetails: data.getUser }
      })
      .catch((err) =&gt; {
        // Fail gracefully
        console.log(err);
        return { userDetails: {} }
      })
    }
  </code></pre>
  
  <p>I set up my getInitialProps function in the index.js file within the pages directory:</p>
  
  <pre><code>  import getUser from '../shared/services/get-user';
  
    static async getInitialProps (context) {
      const results = await getUser(context.apolloClient)
      console.log(results);
      return {}
    }
  </code></pre>
  
  <p><strong>Expected behavior</strong>
  I expect to see a log of the user returned, however I get an ECONNREFUSED error as shown above.</p>
  
  <p>System information
  OS: macOS Mojave
  Browser (if applies) Chrome
  Version of Next.js: 7.0.2
  Version of ApolloClient: 2.4.12l
  Additional context
  Using Absinthe (Elixir+Phoenix) GraphQL API, url specified: <a href="http://localhost:8080/api/graphq" rel="nofollow noreferrer">http://localhost:8080/api/graphq</a>
  Using docker-compose to spin up multiple containers. API and NextJS client are in separate containers sitting behind nginx server. Nginx server routes to relevant container depending on the url endpoint specified. <strong>THIS COULD VERY WELL BE THE ISSUE BUT I CAN'T SEEM TO FIND A SOLUTION TO THIS.</strong> If url contains api, client will be routed to my API container.</p>
  
  <p>Here is the setup for my nginx configuration:</p>
  
  <pre><code>upstream client {
    server client:3000;
  }
  
  upstream api {
    server api:4000;
  }
  
  server {
    listen 80;
  
    location / {
      proxy_pass http://client;
    }
  
    location /sockjs-node {
      proxy_pass http://client;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "Upgrade";
    }
  
    location /api {
      rewrite /api/(.*) /$1 break;
      proxy_pass http://api;
    }
  }
  </code></pre>