Urigo / WhatsApp-Clone-Tutorial

https://www.tortilla.academy/Urigo/WhatsApp-Clone-Tutorial

Home Page:https://tortilla.academy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

(SOLVED) [Server Step 2.3] -- Server requests do nothing, 'hanging'

amunrarara opened this issue · comments

Whenever I initiate any sort of request to the server, be it using the provided curl command, or by visiting http://localhost:4000/graphql in the browser, the request always stalls and provides nothing, not even an error.

I've gone through the project with a fine-tooth comb, and cannot find any deviations in my code from the tutorial.

Here's /index.ts:


import { ApolloServer, gql } from 'apollo-server-express';
import cors from 'cors';
import express from 'express';
import { chats } from './db';
import schema from './schema';

const app = express();

app.use(cors());
app.use(express.json);

app.get('/_ping', (req, res) => {
    res.send('pong');
    res.json(chats);
});

const server = new ApolloServer({
    schema,
    //playground: true,
    //introspection: true,
});

server.applyMiddleware({ app, cors: true, path: '/graphql' });


const port = process.env.PORT || 4000;
//process.env.PLAYGROUND_URL = "http://localhost:4000";

app.listen(port, () => {
    console.log(`Server is listening on port ${port}`);
    //console.log(process.env.NODE_ENV);
})

Here is also /schema/resolvers.ts


import { DateTimeResolver, URLResolver } from 'graphql-scalars';
import { chats, messages } from '../db'

const resolvers = {
    Date: DateTimeResolver,
    URL: URLResolver,

    Chat: {
        lastMessage(chat: any) {
            return messages.find(m => m.id === chat.lastMessage);
        },
    },

    Query: {
        chats() {
            return chats;
        },
    },
};

export default resolvers;

I won't bother copying over /schema/index.ts, nor /schema/typeDefs.graphql, nor /db.ts, since they are identical to the tutorial.

The issue was two lines that I didn't notice were deleted in the tutorial (note: during that step in the tutorial, a different version of the file is being presented; added/deleted lines are not representing the sequential state of the tutorial app):

By removing app.use(cors()) and app.use(express.json), then ApolloServer can do its thing :-) A better description of this would be helpful, but this issue is now resolved.

@amunrarara can you point me to what exactly is missing?