Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createGraphQLSchema } from 'openapi-to-graphql';
import { graphqlHTTP } from 'express-graphql';
import fs from 'fs';
import path from 'path';

const openApiSpec = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../openapi/swagger.json'), 'utf8'));
const graphqlSchema = createGraphQLSchema(openApiSpec);

export default function(app) {
app.use('/graphql', graphqlHTTP({
schema: graphqlSchema,
graphiql: true
}));
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"google-play-scraper": "^10.0.0",
"npm-check-updates": "^16.14.4",
"postman-to-openapi": "^3.0.1",
"swagger-ui-express": "^5.0.0"
"swagger-ui-express": "^5.0.0",
"openapi-to-graphql": "^2.2.0"
},
"devDependencies": {
"eslint": "^8.49.0",
Expand Down
3 changes: 3 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Express from 'express';
import router from './lib/index.js';
import swaggerDocument from './openapi/swagger.json' assert { type: "json" };
import swaggerUi from 'swagger-ui-express';
import setupGraphQL from './lib/graphql.js';

const app = Express();
const port = process.env.PORT || 3000;
Expand All @@ -14,6 +15,8 @@ var options = {

app.use('/openapi.json', Express.static('openapi/swagger.json'));

setupGraphQL(app);

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options));
app.use('/api/', router);

Expand Down