Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 0f74f05

Browse files
danielreardenIvanGoncharov
authored andcommitted
Convert CommonJS module syntax to ES6
1 parent 3ede973 commit 0f74f05

File tree

6 files changed

+175
-179
lines changed

6 files changed

+175
-179
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Just mount `express-graphql` as a route handler:
2828

2929
```js
3030
const express = require('express');
31-
const graphqlHTTP = require('express-graphql');
31+
const { graphqlHTTP } = require('express-graphql');
3232

3333
const app = express();
3434

@@ -49,7 +49,7 @@ Use `.get` or `.post` (or both) rather than `.use` to configure your route handl
4949

5050
```js
5151
const restify = require('restify');
52-
const graphqlHTTP = require('express-graphql');
52+
const { graphqlHTTP } = require('express-graphql');
5353

5454
const app = restify.createServer();
5555

@@ -196,7 +196,7 @@ This example uses [`express-session`][] to provide GraphQL with the currently lo
196196

197197
```js
198198
const session = require('express-session');
199-
const graphqlHTTP = require('express-graphql');
199+
const { graphqlHTTP } = require('express-graphql');
200200

201201
const app = express();
202202

@@ -243,7 +243,7 @@ This example illustrates adding the amount of time consumed by running the
243243
provided query, which could perhaps be used by your development tools.
244244

245245
```js
246-
const graphqlHTTP = require('express-graphql');
246+
const { graphqlHTTP } = require('express-graphql');
247247

248248
const app = express();
249249

@@ -321,9 +321,9 @@ running a GraphQL request. This function is used internally to handle the
321321
incoming request, you may use it directly for building other similar services.
322322

323323
```js
324-
const graphqlHTTP = require('express-graphql');
324+
const { getGraphQLParams } = require('express-graphql');
325325

326-
graphqlHTTP.getGraphQLParams(request).then((params) => {
326+
getGraphQLParams(request).then((params) => {
327327
// do something...
328328
});
329329
```

src/__tests__/http-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
parse,
2727
} from 'graphql';
2828

29-
import graphqlHTTP from '../index';
29+
import { graphqlHTTP } from '../index';
3030

3131
const QueryRootType = new GraphQLObjectType({
3232
name: 'QueryRoot',

src/__tests__/usage-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { expect } from 'chai';
66
import { describe, it } from 'mocha';
77
import { GraphQLSchema } from 'graphql';
88

9-
import graphqlHTTP from '../index';
9+
import { graphqlHTTP } from '../index';
1010

1111
describe('Useful errors when incorrectly used', () => {
1212
it('requires an option factory function', () => {

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ type Middleware = (request: $Request, response: $Response) => Promise<void>;
184184
* Middleware for express; takes an options object or function as input to
185185
* configure behavior, and returns an express middleware.
186186
*/
187-
module.exports = graphqlHTTP;
188-
function graphqlHTTP(options: Options): Middleware {
187+
export function graphqlHTTP(options: Options): Middleware {
189188
if (!options) {
190189
throw new Error('GraphQL middleware requires options.');
191190
}
@@ -456,8 +455,9 @@ export type GraphQLParams = {|
456455
* Provided a "Request" provided by express or connect (typically a node style
457456
* HTTPClientRequest), Promise the GraphQL request parameters.
458457
*/
459-
module.exports.getGraphQLParams = getGraphQLParams;
460-
async function getGraphQLParams(request: $Request): Promise<GraphQLParams> {
458+
export async function getGraphQLParams(
459+
request: $Request,
460+
): Promise<GraphQLParams> {
461461
const { url = '' } = request;
462462
const urlData = new URLSearchParams(url.split('?')[1]);
463463
const bodyData = await parseBody(request);

0 commit comments

Comments
 (0)