Skip to content

Commit

Permalink
Allow for versioned schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
bagelbits committed Dec 28, 2024
1 parent 8f81d25 commit ba24043
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/middleware/apolloServer.ts
Original file line number Diff line number Diff line change
@@ -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: [
Expand Down
9 changes: 5 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -41,21 +42,21 @@ 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<cors.CorsRequest>(),
bodyParser.json(),
expressMiddleware(apolloMiddleware, {
expressMiddleware(apolloMiddleware2014, {
context: async ({ req }) => ({ token: req.headers.token }),
})
);
app.use(
'/graphql/2014',
cors<cors.CorsRequest>(),
bodyParser.json(),
expressMiddleware(apolloMiddleware, {
expressMiddleware(apolloMiddleware2014, {
context: async ({ req }) => ({ token: req.headers.token }),
})
);
Expand Down

0 comments on commit ba24043

Please sign in to comment.