-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (38 loc) · 1.04 KB
/
index.js
File metadata and controls
44 lines (38 loc) · 1.04 KB
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
import express from 'express';
import cors from 'cors';
import http from 'http';
import 'dotenv/config';
import gFunctions from '@google-cloud/functions-framework';
import { ApolloServer } from '@apollo/server';
import { expressMiddleware } from '@apollo/server/express4';
import { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer';
import {
resolvers,
schemas,
contextHandler
} from './graphql/index.js';
import './db/index.js'
const app = express();
const httpServer = http.createServer(app);
// Create the GraphQL server instance
const apolloServer = new ApolloServer({
typeDefs: schemas,
resolvers,
plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],
context: contextHandler,
// Sandbox
introspection: true,
});
await apolloServer.start();
// Integrate GraphQL server with Express
app.use(
'/graphql',
cors(),
express.json(),
expressMiddleware(
apolloServer,
{ context: contextHandler },
),
);
gFunctions.http('graphql', app);
console.log('🚀 Running server on /graphql');