Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
amunrarara opened this issue Apr 14, 2020 · 2 comments
Open

Comments

@amunrarara
Copy link

amunrarara commented Apr 14, 2020

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.

@amunrarara amunrarara changed the title [Server Step 2.3] -- curl command is 'hanging' [Server Step 2.3] -- Server requests do nothing, 'hanging' Apr 14, 2020
@amunrarara
Copy link
Author

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 amunrarara changed the title [Server Step 2.3] -- Server requests do nothing, 'hanging' (SOLVED) [Server Step 2.3] -- Server requests do nothing, 'hanging' Apr 15, 2020
@Urigo
Copy link
Owner

Urigo commented Apr 19, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants