CDLUC3 / dmsp_backend_prototype

The GraphQL (Apollo server) backend for the new DMSP system
0 stars 0 forks source link

Mock store #29

Closed briri closed 1 month ago

briri commented 1 month ago

Added a custom MockStore that can be used in our docker dev environment.

The temporary store is ephemeral and resets when the application restarts.

There are also some changes in the ./data-migrations folder that aren't related to the MockStore. They were added to allow me to seed our database for the new ECS containers

jupiter007 commented 1 month ago

For index.ts, I wonder if we could change the handling of the async to be like the following. It was easier for me to read using async-await.

import { ApolloServer } from '@apollo/server';

import express from 'express';
import http from 'http';

import { logger } from './logger';
import { serverConfig } from './config';
import { healthcheck } from './pages/healthcheck';
import { handleCors } from './middleware/cors';
import { attachApolloServer } from './middleware/express';

// Required logic for integrating with Express
const app = express();
// Our httpServer handles incoming requests to our Express app.
const httpServer = http.createServer(app);

const server = new ApolloServer(serverConfig(logger, httpServer));

const startServer = async () => {
    await server.start();
    const { cache } = server;

    // Healthcheck endpoint (declare this BEFORE CORS definition due to AWS ALB limitations)
    app.get('/up', (_request, response) => healthcheck(server, response, logger));

    // Express middleware
    app.use(
        '/',
        // 50mb is the limit that Apollo `startStandaloneServer` uses.
        express.json({ limit: '50mb' }),
        // CORS config
        handleCors(),
        // Attach Apollo server
        attachApolloServer(server, cache, logger),
    );
    // TODO: Add our auth and token endpoints here

    httpServer.listen({ port: 4000 }, () => {
        console.log(`Server ready at http://localhost:4000/graphql`);
    })
}

startServer().catch((error) => {
    console.log('Error starting server:', error)
})
jupiter007 commented 1 month ago

Also, @briri if you have time on Monday, could you help me figure out why I can't run the data migrations locally? I wanted to try running the app with the mocks, but I wasn't able to get the data.

jupiter007 commented 1 month ago

I'm wondering, in logger.ts, whether you should add another "optional chaining" on line 17, so instead of "httpMethod: context?.request.http?.method,", it is "httpMethod: context?.request?.http?.method".

briri commented 1 month ago

Closing this one since we got the preserveResolver working as expected