Add gqlPath in config for GQL server URL (#483)

This commit is contained in:
Nabarun Gogoi 2023-11-21 15:21:10 +05:30 committed by GitHub
parent 4a88ff76e0
commit 8c44fbbe6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 4 deletions

View File

@ -2,6 +2,7 @@
host = "127.0.0.1"
port = {{port}}
kind = "{{watcherKind}}"
gqlPath = "/graphql"
# Checkpointing state.
checkpointing = true

View File

@ -200,6 +200,7 @@ export interface ServerConfig {
host: string;
port: number;
mode: string;
gqlPath: string;
kind: string;
enableConfigValidation: boolean;
checkpointing: boolean;

View File

@ -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<ApolloServer> => {
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}`);