Express-graphql: broken import for typescript

Created on 8 Jun 2016  路  4Comments  路  Source: graphql/express-graphql

Unable to require the module using import in Typescript after this change: #92 . It compiles, but seems like the module doesn't have any default export.

Code:

import graphqlHTTP from 'express-graphql';
import schema from './schema';

const graphqlMiddleware:any = graphqlHTTP({
  graphiql: true,
  pretty: true,
  schema: schema,
});

runtime error:

const graphqlMiddleware = express_graphql_1.default({
                                                                           ^
TypeError: express_graphql_1.default is not a function

tsconfig:

"compilerOptions": {
        "target": "es2015",
        "module": "commonjs",
        "moduleResolution": "node"
}

Most helpful comment

You can import graphqlHTTP using the following import statement:
import * as graphqlHTTP from 'express-graphql';

All 4 comments

It's a problem with DefinitelyTyped. Specifically these lines:

    /**
     * Middleware for express; takes an options object or function as input to
     * configure behavior, and returns an express middleware.
     */
    export default function graphqlHTTP(options: Options): Middleware;

Ideally, it should be:

  var graphqlHTTP: (options: Options) => Middleware;

  /**
   * Middleware for express; takes an options object or function as input to
   * configure behavior, and returns an express middleware.
   */
  export = graphqlHTTP;

You can import graphqlHTTP using the following import statement:
import * as graphqlHTTP from 'express-graphql';

Closing this here since it sounds like a bug in that repo

Was this page helpful?
0 / 5 - 0 ratings

Related issues

macin40 picture macin40  路  4Comments

justinmchase picture justinmchase  路  4Comments

arunoda picture arunoda  路  4Comments

jamesmoriarty picture jamesmoriarty  路  4Comments

phuchle2 picture phuchle2  路  3Comments