Skip to content

Commit a4792e0

Browse files
committed
migrate to graphql-yoga
1 parent 9e69941 commit a4792e0

File tree

3 files changed

+449
-1080
lines changed

3 files changed

+449
-1080
lines changed

index.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const express = require('express')
2-
const { graphqlHTTP } = require('express-graphql')
31
const { createGraphQLSchema } = require('openapi-to-graphql');
2+
const { createServer } = require('node:http')
3+
const { createYoga } = require('graphql-yoga')
44
const request = require('request')
55
const yaml = require('js-yaml');
66
const port = process.env.PORT || 8080;
@@ -12,17 +12,18 @@ async function main(oas) {
1212
'User-Agent': 'AdoptOpenJDK GraphQL Server'
1313
}
1414
})
15+
16+
// Create a Yoga instance with a GraphQL schema.
17+
const yoga = createYoga({ schema })
18+
19+
// Pass it into a server to hook into request handlers.
20+
const server = createServer(yoga)
21+
1522

16-
// server schema:
17-
const app = express()
18-
app.use(
19-
'/graphql',
20-
graphqlHTTP({
21-
schema,
22-
graphiql: true
23-
})
24-
)
25-
app.listen(port)
23+
// Start the server and you're done!
24+
server.listen(port, () => {
25+
console.info(`Server is running on http://localhost:${port}/graphql`)
26+
})
2627
}
2728

2829
request('https://api.adoptopenjdk.net/openapi', function (error, response, body) {

0 commit comments

Comments
 (0)