diff --git a/packages/codegen/src/templates/config-template.handlebars b/packages/codegen/src/templates/config-template.handlebars index 12447fb34..2ec001812 100644 --- a/packages/codegen/src/templates/config-template.handlebars +++ b/packages/codegen/src/templates/config-template.handlebars @@ -2,6 +2,7 @@ host = "127.0.0.1" port = {{port}} kind = "{{watcherKind}}" + gqlPath = "/graphql" # Checkpointing state. checkpointing = true diff --git a/packages/util/src/config.ts b/packages/util/src/config.ts index 1b797897e..0fa067d64 100644 --- a/packages/util/src/config.ts +++ b/packages/util/src/config.ts @@ -200,6 +200,7 @@ export interface ServerConfig { host: string; port: number; mode: string; + gqlPath: string; kind: string; enableConfigValidation: boolean; checkpointing: boolean; diff --git a/packages/util/src/server.ts b/packages/util/src/server.ts index 8c5099414..a7645a761 100644 --- a/packages/util/src/server.ts +++ b/packages/util/src/server.ts @@ -3,7 +3,10 @@ import { ApolloServer } from 'apollo-server-express'; import { createServer } from 'http'; import { WebSocketServer } from 'ws'; import { useServer } from 'graphql-ws/lib/use/ws'; -import { ApolloServerPluginDrainHttpServer, ApolloServerPluginLandingPageLocalDefault } from 'apollo-server-core'; +import { + ApolloServerPluginDrainHttpServer, + ApolloServerPluginLandingPageLocalDefault +} from 'apollo-server-core'; import debug from 'debug'; import responseCachePlugin from 'apollo-server-plugin-response-cache'; import { InMemoryLRUCache } from '@apollo/utils.keyvaluecache'; @@ -18,6 +21,8 @@ import { PaymentsManager, paymentsPlugin } from './payments'; const log = debug('vulcanize:server'); +const DEFAULT_GQL_PATH = '/graphql'; + export const createAndStartServer = async ( app: Application, typeDefs: TypeSource, @@ -25,7 +30,14 @@ export const createAndStartServer = async ( serverConfig: ServerConfig, paymentsManager?: PaymentsManager ): Promise => { - const { host, port, gqlCache: gqlCacheConfig, maxSimultaneousRequests, maxRequestQueueLimit } = serverConfig; + const { + host, + port, + gqlCache: gqlCacheConfig, + maxSimultaneousRequests, + maxRequestQueueLimit, + gqlPath = DEFAULT_GQL_PATH + } = serverConfig; app.use(queue({ activeLimit: maxSimultaneousRequests || 1, queuedLimit: maxRequestQueueLimit || -1 })); @@ -38,7 +50,7 @@ export const createAndStartServer = async ( // Create our WebSocket server using the HTTP server we just set up. const wsServer = new WebSocketServer({ server: httpServer, - path: '/graphql' + path: gqlPath }); const serverCleanup = useServer({ schema }, wsServer); @@ -73,8 +85,13 @@ export const createAndStartServer = async ( ApolloServerPluginLandingPageLocalDefault({ embed: true }) ] }); + await server.start(); - server.applyMiddleware({ app }); + + server.applyMiddleware({ + app, + path: gqlPath + }); httpServer.listen(port, host, () => { log(`Server is listening on ${host}:${port}${server.graphqlPath}`);