Skip to content

Commit

Permalink
feat: added driveId as param to new graphql route
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed Jan 22, 2024
1 parent 675994f commit 8bb3255
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions api/src/graphql/server.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { Server } from 'http';
import { createServer as createHttpServer } from 'http';
import type express from 'express';
import { ApolloServerPlugin, ApolloServer } from '@apollo/server';
import { expressMiddleware } from '@apollo/server/express4';
import { ApolloServerPluginLandingPageDisabled } from '@apollo/server/plugin/disabled';
import bodyParser from 'body-parser';
import cookierParser from 'cookie-parser';
import cors from 'cors';
import { PORT } from '../env';
import { schemaWithMiddleware } from './schema';
import { Context, createContext } from './context';
import { getChildLogger } from '../logger';
import type { Server } from "http";
import { createServer as createHttpServer } from "http";
import type express from "express";
import { ApolloServerPlugin, ApolloServer } from "@apollo/server";
import { expressMiddleware } from "@apollo/server/express4";
import { ApolloServerPluginLandingPageDisabled } from "@apollo/server/plugin/disabled";
import bodyParser from "body-parser";
import cookierParser from "cookie-parser";
import cors from "cors";
import { PORT } from "../env";
import { schemaWithMiddleware } from "./schema";
import { Context, createContext } from "./context";
import { getChildLogger } from "../logger";

const logger = getChildLogger({ msgPrefix: 'SERVER' });
const logger = getChildLogger({ msgPrefix: "SERVER" });

function loggerPlugin(): ApolloServerPlugin<Context> {
return {
Expand All @@ -28,28 +28,39 @@ function loggerPlugin(): ApolloServerPlugin<Context> {
};
}

const createApolloServer = (): ApolloServer<Context> => new ApolloServer<Context>({
schema: schemaWithMiddleware,
introspection: true,
plugins: [ApolloServerPluginLandingPageDisabled(), loggerPlugin()],
});
const createApolloServer = (): ApolloServer<Context> =>
new ApolloServer<Context>({
schema: schemaWithMiddleware,
introspection: true,
plugins: [ApolloServerPluginLandingPageDisabled(), loggerPlugin()],
});

export const startServer = async (
app: express.Application,
app: express.Application
): Promise<Server> => {
logger.debug('Starting server');
logger.debug("Starting server");
const httpServer = createHttpServer(app);
const apollo = createApolloServer();

await apollo.start();
app.use(
'/graphql',
"/graphql",
cors<cors.CorsRequest>(),
cookierParser(undefined, { decode: (value: string) => value }),
bodyParser.json(),
expressMiddleware(apollo, {
context: async (params) => createContext(params),
})
);

app.use(
"/:driveId/graphql",
cors<cors.CorsRequest>(),
cookierParser(undefined, { decode: (value: string) => value }),
bodyParser.json(),
expressMiddleware(apollo, {
context: async (params) => (createContext(params)),
}),
context: async (params) => createContext(params),
})
);

return httpServer.listen({ port: PORT }, () => {
Expand Down

0 comments on commit 8bb3255

Please sign in to comment.