-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
68 lines (59 loc) · 1.85 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
61
62
63
64
65
66
67
68
import "reflect-metadata";
import { buildSchema } from "type-graphql";
import { ApolloServer } from "apollo-server";
import path from "path";
import { PrismaClient } from "@prisma/client";
import { resolvers } from "./prisma/generated/type-graphql";
import bcrypt from "bcrypt";
import {
ApolloServerPluginLandingPageLocalDefault,
ApolloServerPluginLandingPageProductionDefault
} from "apollo-server-core";
interface Context {
prisma: PrismaClient;
}
async function main() {
console.log('NODE_ENV', process.env.NODE_ENV);
const schema = await buildSchema({
resolvers,
emitSchemaFile: path.resolve(__dirname, "./generated-schema.graphql"),
validate: false,
});
const prisma = new PrismaClient({
log: [
{
emit: 'stdout',
level: 'query',
},
{
emit: 'stdout',
level: 'error',
},
{
emit: 'stdout',
level: 'info',
},
{
emit: 'stdout',
level: 'warn',
},
],
});
await prisma.$connect();
const server = new ApolloServer({
schema,
context: (): Context => ({ prisma }),
// https://www.apollographql.com/blog/graphql/security/why-you-should-disable-graphql-introspection-in-production/#:~:text=You%20can%20turn%20off%20introspection,%2C%20resolvers%2C%20introspection%3A%20process.
introspection: process.env.NODE_ENV !== 'production',
plugins: [
// Install a landing page plugin based on NODE_ENV
process.env.NODE_ENV === "production" ? ApolloServerPluginLandingPageProductionDefault({ footer: false }): ApolloServerPluginLandingPageLocalDefault({ footer: false, embed: true }),
],
});
const hashedpassword = bcrypt.hashSync('password', 8);
console.log(hashedpassword);
server.listen(4000).then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});
}
main().catch(console.error);