Skip to content

Commit

Permalink
Fix GraphQL 16 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Jul 25, 2024
1 parent 09ebb7e commit 572ed6d
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 70 deletions.
23 changes: 20 additions & 3 deletions bin/json-graphql-server.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ require('reify');
var path = require('path');
var express = require('express');
var cors = require('cors');
var JsonGraphqlServer = require('../dist/json-graphql-server-node').default;

var JsonGraphqlServer = require('../dist/json-graphql-server-node.cjs').default;
var ruru = require('ruru/server');
var dataFilePath = process.argv.length > 2 ? process.argv[2] : './data.json';
var data = require(path.join(process.cwd(), dataFilePath));
var PORT = process.env.NODE_PORT || 3000;
Expand All @@ -23,7 +23,24 @@ process.argv.forEach((arg, index) => {
});

app.use(cors());
app.use('/', JsonGraphqlServer(data));
const gqlServer = JsonGraphqlServer(data);
const graphiql = (req, res) => {
res.writeHead(200, undefined, {
"Content-Type": "text/html; charset=utf-8",
});
return res.end(
ruru.ruruHTML({
endpoint: '/graphql',
})
);
}
app.use('/', (req, res) => {
if (req.is('application/json')) {
return gqlServer(req, res);
}

return graphiql(req, res);
});
app.listen(PORT, HOST);
var msg = `GraphQL server running with your data at http://${HOST}:${PORT}/`;
console.log(msg); // eslint-disable-line no-console
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,17 @@
"@graphql-tools/schema": "^10.0.3",
"cors": "^2.8.5",
"express": "^4.17.3",
"express-graphql": "^0.9.0",
"graphql": "^16.8.1",
"graphql-http": "^1.22.1",
"graphql-tag": "^2.12.6",
"graphql-type-json": "^0.3.2",
"inflection": "^3.0.0",
"lodash.merge": "^4.6.2",
"reify": "^0.20.12",
"ruru": "^2.0.0-beta.13",
"xhr-mock": "^2.5.1"
},
"bin": {
"json-graphql-server": "bin/json-graphql-server.js"
"json-graphql-server": "bin/json-graphql-server.cjs"
}
}
2 changes: 1 addition & 1 deletion src/introspection/getTypeFromValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
GraphQLNonNull,
GraphQLString,
} from 'graphql';
import GraphQLJSON from 'graphql-type-json';
import { GraphQLJSON } from 'graphql-type-json';
import DateType, { isISODateString } from './DateType';

const isNumeric = (value) => !isNaN(parseFloat(value)) && isFinite(value);
Expand Down
5 changes: 2 additions & 3 deletions src/jsonGraphqlExpress.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import graphqlHTTP from 'express-graphql';
import { createHandler } from 'graphql-http/lib/use/express';
import schemaBuilder from './schemaBuilder';

/**
Expand Down Expand Up @@ -46,7 +46,6 @@ import schemaBuilder from './schemaBuilder';
* app.listen(PORT);
*/
export default (data) =>
graphqlHTTP({
createHandler({
schema: schemaBuilder(data),
graphiql: true,
});
2 changes: 1 addition & 1 deletion src/resolver/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pluralize } from 'inflection';
import GraphQLJSON from 'graphql-type-json';
import { GraphQLJSON } from 'graphql-type-json';

import all from './Query/all';
import meta from './Query/meta';
Expand Down
Loading

0 comments on commit 572ed6d

Please sign in to comment.