Skip to content

Commit 572ed6d

Browse files
committed
Fix GraphQL 16 compatibility
1 parent 09ebb7e commit 572ed6d

File tree

6 files changed

+131
-70
lines changed

6 files changed

+131
-70
lines changed

bin/json-graphql-server.cjs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ require('reify');
33
var path = require('path');
44
var express = require('express');
55
var cors = require('cors');
6-
var JsonGraphqlServer = require('../dist/json-graphql-server-node').default;
7-
6+
var JsonGraphqlServer = require('../dist/json-graphql-server-node.cjs').default;
7+
var ruru = require('ruru/server');
88
var dataFilePath = process.argv.length > 2 ? process.argv[2] : './data.json';
99
var data = require(path.join(process.cwd(), dataFilePath));
1010
var PORT = process.env.NODE_PORT || 3000;
@@ -23,7 +23,24 @@ process.argv.forEach((arg, index) => {
2323
});
2424

2525
app.use(cors());
26-
app.use('/', JsonGraphqlServer(data));
26+
const gqlServer = JsonGraphqlServer(data);
27+
const graphiql = (req, res) => {
28+
res.writeHead(200, undefined, {
29+
"Content-Type": "text/html; charset=utf-8",
30+
});
31+
return res.end(
32+
ruru.ruruHTML({
33+
endpoint: '/graphql',
34+
})
35+
);
36+
}
37+
app.use('/', (req, res) => {
38+
if (req.is('application/json')) {
39+
return gqlServer(req, res);
40+
}
41+
42+
return graphiql(req, res);
43+
});
2744
app.listen(PORT, HOST);
2845
var msg = `GraphQL server running with your data at http://${HOST}:${PORT}/`;
2946
console.log(msg); // eslint-disable-line no-console

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,17 @@
6161
"@graphql-tools/schema": "^10.0.3",
6262
"cors": "^2.8.5",
6363
"express": "^4.17.3",
64-
"express-graphql": "^0.9.0",
6564
"graphql": "^16.8.1",
65+
"graphql-http": "^1.22.1",
6666
"graphql-tag": "^2.12.6",
6767
"graphql-type-json": "^0.3.2",
6868
"inflection": "^3.0.0",
6969
"lodash.merge": "^4.6.2",
7070
"reify": "^0.20.12",
71+
"ruru": "^2.0.0-beta.13",
7172
"xhr-mock": "^2.5.1"
7273
},
7374
"bin": {
74-
"json-graphql-server": "bin/json-graphql-server.js"
75+
"json-graphql-server": "bin/json-graphql-server.cjs"
7576
}
7677
}

src/introspection/getTypeFromValues.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
GraphQLNonNull,
88
GraphQLString,
99
} from 'graphql';
10-
import GraphQLJSON from 'graphql-type-json';
10+
import { GraphQLJSON } from 'graphql-type-json';
1111
import DateType, { isISODateString } from './DateType';
1212

1313
const isNumeric = (value) => !isNaN(parseFloat(value)) && isFinite(value);

src/jsonGraphqlExpress.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import graphqlHTTP from 'express-graphql';
1+
import { createHandler } from 'graphql-http/lib/use/express';
22
import schemaBuilder from './schemaBuilder';
33

44
/**
@@ -46,7 +46,6 @@ import schemaBuilder from './schemaBuilder';
4646
* app.listen(PORT);
4747
*/
4848
export default (data) =>
49-
graphqlHTTP({
49+
createHandler({
5050
schema: schemaBuilder(data),
51-
graphiql: true,
5251
});

src/resolver/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { pluralize } from 'inflection';
2-
import GraphQLJSON from 'graphql-type-json';
2+
import { GraphQLJSON } from 'graphql-type-json';
33

44
import all from './Query/all';
55
import meta from './Query/meta';

0 commit comments

Comments
 (0)