-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
60 lines (47 loc) · 1.64 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { makeExecutableSchema } from "@graphql-tools/schema";
import { ApolloServer } from '@apollo/server';
import { addMocksToSchema } from '@graphql-tools/mock';
import { startStandaloneServer } from '@apollo/server/standalone';
import fs from "node:fs";
import { baselineMocks } from "./base_mocks";
const noopResolvers = {
Query: {},
Mutation: {}
}
const loadSchemaDef = async (): Promise<string> => {
const fPath = process.env["ATM_TYPE_DEFS_PATH"] ?? `${import.meta.dir}/schema.graphql`;
console.log(`Loading schema def from ${fPath}`);
if (!fs.existsSync(fPath)) {
console.log(`Unable to load schema file at ${fPath}, type definitions file required`);
process.exit(2);
}
//This should be able to use Bun.file() but for some reason things crash really hard in docker...
const fileData = fs.readFileSync(fPath);
return fileData.toString();
}
const schemaDef = await loadSchemaDef();
const schema = makeExecutableSchema({
typeDefs: schemaDef,
resolvers: noopResolvers
});
let customMocks = {};
const mocksPath = process.env["ATM_CUSTOM_MOCKS_PATH"] ?? `${import.meta.dir}/custom-mocks.ts`;
if (fs.existsSync(mocksPath)) {
customMocks = (await import(mocksPath)).default;
}
const mocks = {
...baselineMocks,
...customMocks
};
const server = new ApolloServer({
schema: addMocksToSchema({schema, mocks}),
});
console.log("Starting standalone server with mock schema");
const port = process.env["PORT"] ? parseInt(process.env["PORT"]) : 8080;
startStandaloneServer(
server,
{
listen: {port}
}
);
console.log(`🚀 Server ready at: http://localhost:${port}/graphql`);