Skip to content

Responses from createHandler in express are not returned #74

@mjmahone

Description

@mjmahone

I tried to implement the code sample for express in order to migrate away from express-graphql. The express-graphql version works and returns a response, but the http-graphql version does not respond.

Code:

import * as express from 'express';
import { graphqlHTTP } from 'express-graphql';
import { GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql';
import { createHandler } from 'graphql-http/lib/use/express';

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: "Query", 
    fields: {hello: {type: GraphQLString, resolve: () => "hello"}}
  })
});
const app = express();

// express-graphql implementation
app.use('/graphql', graphqlHTTP({ schema: schema }));

// graphql-http express implementation
app.all('/graphql2', createHandler({ schema }));
app.listen(4000);

The I use curl:

curl http://localhost:4000/graphql --data-urlencode "query=query Q { hello }"
{"data":{"hello":"hello"}}

curl http://localhost:4000/graphql2 --data-urlencode "query=query Q { hello }"

Expected Behaviour
A response of {"data":{"hello":"hello"}} for both /graphql and /graphql2.

Actual Behaviour
Only /graphql (the express-graphql implementation) returns any response.

Version: 1.17.1
Node version: 16.14.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions