Apollo GraphQL: Setting Port for HTTPBatchedNetworkInterface?

380 views Asked by At

I'm trying to connect to a local dev environment via an IP address. I'm getting an error because HTTPBatchedNetworkInterface shows:

_uri: "http://10.0.1.10/graphql"

...when it needs to be:

"http://10.0.1.10:3000/graphql"

Here's my server-side setup code:

const localHostString = '10.0.1.10';
const METEOR_PORT = 3000;
const GRAPHQL_PORT = 4000;
const server = express();

server.use('*', cors({ origin: `http://${localHostString}:${METEOR_PORT}` }));


server.use('/graphql', bodyParser.json(), graphqlExpress({
    schema,
    context
}));

server.use('/graphiql', graphiqlExpress({
    endpointURL: '/graphql',
    subscriptionsEndpoint: `ws://${localHostString}:${GRAPHQL_PORT}/subscriptions`
}));

// Wrap the Express server
const ws = createServer(server);
ws.listen(GRAPHQL_PORT, () => {
    console.log(`GraphQL Server is now running on http://${localHostString}:${GRAPHQL_PORT}`);
    console.log(`GraphiQL available at http://${localHostString}:${GRAPHQL_PORT}/graphiql`);
    // Set up the WebSocket for handling GraphQL subscriptions
    new SubscriptionServer({
        execute,
        subscribe,
        schema
    }, {
        server: ws,
        path: '/subscriptions',
    });
});

What is the correct way to get the port number into HTTPBatchedNetworkInterface._uri?

Thanks in advance to all for any info.

1

There are 1 answers

0
VikR On

Fixed. My framework is Meteor and I had to set ROOT_URL = 10.0.1.10:3000/.