Skip to content

Commit 7a32653

Browse files
Copilotelecterious
andcommitted
Fix Apollo Server initialization and add graphql-tag dependency
Co-authored-by: electerious <499088+electerious@users.noreply.github.com>
1 parent 6c1d868 commit 7a32653

14 files changed

Lines changed: 32 additions & 31 deletions

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"express": "^4.21.2",
4545
"graphql": "^16.6.0",
4646
"graphql-scalars": "^1.20.1",
47+
"graphql-tag": "^2.12.6",
4748
"is-url": "^1.2.4",
4849
"is-valid-domain": "^0.1.6",
4950
"mongoose": "^8.19.3",

src/server.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const http = require('http')
34
const express = require('express')
45
const { resolve } = require('path')
56
const { readFile } = require('fs').promises
@@ -103,29 +104,25 @@ const apolloServer = createApolloServer(ApolloServer, {
103104
formatError: handleGraphError,
104105
})
105106

106-
// Variable to track if Apollo Server has started
107-
let apolloServerReady = false
108-
109-
// Start Apollo Server
110-
apolloServer.start().then(() => {
111-
apolloServerReady = true
112-
signale.success('Apollo Server started')
113-
})
107+
// Start Apollo Server asynchronously
108+
const apolloServerStarted = apolloServer.start()
109+
.then(() => {
110+
signale.success('Apollo Server started')
111+
})
114112
.catch((error) => {
115113
signale.fatal('Failed to start Apollo Server:', error)
116114
process.exit(1)
117115
})
118116

119117
// GraphQL endpoint - wait for server to start before processing
120118
app.use('/api', express.json(), async (request, response, next) => {
121-
if (!apolloServerReady) {
122-
await apolloServer.start()
123-
apolloServerReady = true
124-
}
125-
next()
126-
}, expressMiddleware(apolloServer, {
127-
context: createExpressContext,
128-
}))
119+
// Ensure Apollo Server is started
120+
await apolloServerStarted
121+
// Call expressMiddleware after server is started
122+
return expressMiddleware(apolloServer, {
123+
context: createExpressContext,
124+
})(request, response, next)
125+
})
129126

130127
// Health check endpoint
131128
app.get('/.well-known/apollo/server-health', (request, response) => {
@@ -153,4 +150,7 @@ app.use((error, request, response) => {
153150
response.status(error.statusCode).send(error.message)
154151
})
155152

156-
module.exports = app
153+
// Create HTTP server
154+
const server = http.createServer(app)
155+
156+
module.exports = server

src/types/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { gql } = require('@apollo/server')
3+
const { gql } = require('graphql-tag')
44

55
module.exports = gql`
66
"""

src/types/domainStatistics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { gql } = require('@apollo/server')
3+
const { gql } = require('graphql-tag')
44

55
module.exports = gql`
66
enum ViewType {

src/types/domains.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { gql } = require('@apollo/server')
3+
const { gql } = require('graphql-tag')
44

55
module.exports = gql`
66
"""

src/types/eventStatistics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { gql } = require('@apollo/server')
3+
const { gql } = require('graphql-tag')
44

55
module.exports = gql`
66
enum EventChartType {

src/types/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { gql } = require('@apollo/server')
3+
const { gql } = require('graphql-tag')
44

55
module.exports = gql`
66
enum EventType {

src/types/facts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { gql } = require('@apollo/server')
3+
const { gql } = require('graphql-tag')
44

55
module.exports = gql`
66
type AverageViews {

src/types/miscellaneous.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { gql } = require('@apollo/server')
3+
const { gql } = require('graphql-tag')
44

55
module.exports = gql`
66
scalar URL

0 commit comments

Comments
 (0)