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

Commit

Permalink
Enable the Engine proxy and observe queries on Engine #graphql-in-pro…
Browse files Browse the repository at this point in the history
…duction

[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/)
  • Loading branch information
rdickert authored and pauldowman committed Mar 16, 2018
1 parent 93417e1 commit 7053d67
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions api/src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { createServer } from 'http';
import { SubscriptionServer } from 'subscriptions-transport-ws';
import { execute, subscribe } from 'graphql';
import { Engine } from 'apollo-engine';
import passport from 'passport';
import typeDefs from '../typeDefs';
import resolvers from '../resolvers';
Expand All @@ -28,6 +29,7 @@ const {
WS_PORT = parseInt(PORT, 10) + 1,
MONGO_PORT = parseInt(PORT, 10) + 2,
MONGO_URL = `mongodb://localhost:${MONGO_PORT}/database`,
ENGINE_API_KEY,
} = process.env;

const startServer = async () => {
Expand Down Expand Up @@ -75,6 +77,22 @@ const startServer = async () => {
}),
});

// IMPORTANT: you also need to set the port in api/.env to PORT=9000 in

const engine = new Engine({
engineConfig: {
apiKey: ENGINE_API_KEY,
frontends: [
{
host: '127.0.0.1',
port: 8080,
endpoint: '/graphql',
},
],
},
});
await engine.start();

const db = await MongoClient.connect(MONGO_URL);

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

const server = express();

server.use(engine.expressMiddleware());

server.use(cors());

server.use(bodyParser.json());
Expand Down

0 comments on commit 7053d67

Please sign in to comment.