From ba24043ac5022f7f308abacca2d23f17caea7df8 Mon Sep 17 00:00:00 2001 From: Christopher Ward Date: Fri, 27 Dec 2024 18:18:20 -0800 Subject: [PATCH] Allow for versioned schemas --- src/middleware/apolloServer.ts | 3 +-- src/server.ts | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/middleware/apolloServer.ts b/src/middleware/apolloServer.ts index d5d59059..9eb151a8 100644 --- a/src/middleware/apolloServer.ts +++ b/src/middleware/apolloServer.ts @@ -1,9 +1,8 @@ import { ApolloServer } from '@apollo/server'; import { ApolloServerPluginCacheControl } from '@apollo/server/plugin/cacheControl'; import depthLimit from 'graphql-depth-limit'; -import schema from '../graphql/2014/schema.js'; -const createApolloMiddleware = async () => { +const createApolloMiddleware = async (schema: any) => { const server = new ApolloServer({ schema, plugins: [ diff --git a/src/server.ts b/src/server.ts index ef4d94c9..3c70ebfb 100644 --- a/src/server.ts +++ b/src/server.ts @@ -11,6 +11,7 @@ import morgan from 'morgan'; import docsController from './controllers/docsController.js'; import path from 'path'; import rateLimit from 'express-rate-limit'; +import schema2014 from './graphql/2014/schema.js'; const __filename = fileURLToPath(import.meta.url); @@ -41,13 +42,13 @@ export default async () => { app.use(limiter); console.log('Setting up Apollo GraphQL server'); - const apolloMiddleware = await createApolloMiddleware(); - await apolloMiddleware.start(); + const apolloMiddleware2014 = await createApolloMiddleware(schema2014); + await apolloMiddleware2014.start(); app.use( '/graphql', cors(), bodyParser.json(), - expressMiddleware(apolloMiddleware, { + expressMiddleware(apolloMiddleware2014, { context: async ({ req }) => ({ token: req.headers.token }), }) ); @@ -55,7 +56,7 @@ export default async () => { '/graphql/2014', cors(), bodyParser.json(), - expressMiddleware(apolloMiddleware, { + expressMiddleware(apolloMiddleware2014, { context: async ({ req }) => ({ token: req.headers.token }), }) );