-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
35 lines (28 loc) · 917 Bytes
/
server.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
import { ApolloServer } from '@apollo/server';
import { buildSubgraphSchema } from '@apollo/subgraph';
import { resolvers } from './src/resolvers';
import {gql} from 'graphql-tag';
import { readFileSync } from 'fs';
import responseCachePlugin from '@apollo/server-plugin-response-cache';
const schema = gql(readFileSync('./src/schema.graphql', { encoding: 'utf-8' }));
import { startStandaloneServer } from '@apollo/server/standalone';
import dotenv from 'dotenv';
dotenv.config();
const PORT = parseInt(process.env.PORT!) || 4000;
async function bootstrap() {
const server = new ApolloServer({
schema: buildSubgraphSchema({
typeDefs: schema,
resolvers,
}),
introspection: true,
plugins: [responseCachePlugin()]
})
const { url } = await startStandaloneServer(server, {
listen: {
port: PORT
}
})
console.log(`GraphQL Server started at ${url}`);
}
bootstrap();