http-proxy-middleware and graphql

http-proxy-middleware and graphql


0

I have a simple graphql-server:

const typeDefs = gql`
    type Message {
        id: ID!
        text: String!
    }

    type Query {
        getMessage: Message
    }
`;

const resolvers = {
    Query: {
        getMessage: () => {
            return {
                id: '1',
                text: 'Hello, World!'
            };
        }
    }
};

async function startServer() {
    const server = new ApolloServer({ typeDefs, resolvers });
    await server.start();
    const app = express();
    app.use(cors());
    app.use(express.json());
    server.applyMiddleware({ app });
    const port = 4000;
    app.listen({ port }, () => console.log(`Server is running at https://localhost:${port}${server.graphqlPath}`));
}
startServer();

I created an gateway-server in which I configured request redirection to graphql-server:

     app.use(
            '/graphql',
            createProxyMiddleware({
                target: 'https://localhost:4000/graphql',
                changeOrigin: true,
                pathRewrite: {
                    '^/graphql': '/',
                },
                logLevel: 'debug',
            }),
        );

My problem is that the request goes into endless loading and nothing happens. There are no errors. What am I doing wrong?

If you make queries directly to the graphql server, everything works fine.


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *