```const { GraphQLServer } = require('graphql-yoga...
# orm-help
m
Copy code
const { GraphQLServer } = require('graphql-yoga');
const { importSchema } = require('graphql-import');
const { ApolloEngine } = require('apollo-engine');
const { Prisma } = require('prisma-binding');

const server = new GraphQLServer({
  typeDefs: importSchema('./datamodel.graphql'),
  context: req => ({
    ...req,
    db: new Prisma({
      endpoint: process.env.PRISMA_ENDPOINT,
      debug: true,
    }),
  }),
});

const port = parseInt(process.env.PORT, 10) || 4000;

if (process.env.ENGINE_API_KEY) {
  const engine = new ApolloEngine({
    apiKey: process.env.ENGINE_API_KEY,
  });

  const httpServer = server.createHttpServer({
    tracing: true,
    cacheControl: true,
  });

  engine.on('error', err => {
    console.log('There was an error starting the server or Engine.');
    console.error(err);

    // The app failed to start, should probably kill the server
    process.exit(1);
  });

  engine.listen({ port, httpServer, graphqlPaths: ['/'] }, () =>
    console.log(
      `Server with Apollo Engine is running on <http://localhost:${port}>`,
    ),
  );
} else {
  server.start({ port }, () =>
    console.log(`Server is running on <http://localhost:${port}`>),
  );
}