I have created few tabs to show example queries on GraphQL playground. While adding tabs I need to set the endpoint/server URL as well, where the queries will be executing actually. Below is my code:
const startServer = async () => {
const server = new ApolloServer({
schema,
introspection: true,
playground: {
tabs: [{
name: 'data analysis',
endpoint: '', // want to set the server url here
query: '{ ... }'
}
]
}
});
server.listen(PORT);
};
I can set the hardcoded URL for production but I don't want to do that. I want to set it dynamically according to the environment (localhost, dev, production). One way I tried is to get the URL once the server started listening to the port but it is always http://localhost:PORT, which is not correct. Any idea how can I get production server URL dynamically to set over here. I am working in Node.js. Any help would be appreciating.