Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 7053d67

Browse files
rdickertpauldowman
authored andcommitted
Enable the Engine proxy and observe queries on Engine #graphql-in-production
[API] ### Instructions 1. Create a new Engine instance and put it in front of your app 2. Start the Engine proxy server 3. Add the Engine middleware to the Express server 4. Confirm that the app works as before 5. Go to Engine and observe your queries! Compare database fields with external api calls, etc. --- ### Tips - Edit `api/src/server/index.js` and `api/.env` - You'll need your Engine API Key that you got at the beginning of the training - Change the app's port number so the proxy can accept network requests on its behalf. - Look at the previous slides for inspiration ### Docs - [Engine docs](http://engine-docs.apollographql.com/) - [Engine package](https://github.com/apollographql/apollo-engine-js) - [Engine website](https://engine.apollographql.com/)
1 parent 93417e1 commit 7053d67

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

api/src/server/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { createServer } from 'http';
1515
import { SubscriptionServer } from 'subscriptions-transport-ws';
1616
import { execute, subscribe } from 'graphql';
17+
import { Engine } from 'apollo-engine';
1718
import passport from 'passport';
1819
import typeDefs from '../typeDefs';
1920
import resolvers from '../resolvers';
@@ -28,6 +29,7 @@ const {
2829
WS_PORT = parseInt(PORT, 10) + 1,
2930
MONGO_PORT = parseInt(PORT, 10) + 2,
3031
MONGO_URL = `mongodb://localhost:${MONGO_PORT}/database`,
32+
ENGINE_API_KEY,
3133
} = process.env;
3234

3335
const startServer = async () => {
@@ -75,6 +77,22 @@ const startServer = async () => {
7577
}),
7678
});
7779

80+
// IMPORTANT: you also need to set the port in api/.env to PORT=9000 in
81+
82+
const engine = new Engine({
83+
engineConfig: {
84+
apiKey: ENGINE_API_KEY,
85+
frontends: [
86+
{
87+
host: '127.0.0.1',
88+
port: 8080,
89+
endpoint: '/graphql',
90+
},
91+
],
92+
},
93+
});
94+
await engine.start();
95+
7896
const db = await MongoClient.connect(MONGO_URL);
7997

8098
const createContext = () => ({
@@ -87,6 +105,8 @@ const startServer = async () => {
87105

88106
const server = express();
89107

108+
server.use(engine.expressMiddleware());
109+
90110
server.use(cors());
91111

92112
server.use(bodyParser.json());

0 commit comments

Comments
 (0)