Coco
Coco

Reputation: 1630

setting up graphQL on OpenShift

I'm learning how to set up a server on OpenShift that uses node, express, GraphQL and Postgres and I need some help.

When trying to set up the GraphQL Server I've been following this and it works on my local machine:

import Express from 'express';
import GraphQL from 'express-graphql';
import Schema from './db/GQLschema';

const app = Express();

app.use('/graphql', GraphQL({
    schema: Schema,
    pretty: true,
    graphiql: true
}));
...

I'm using the server.js template provided by OpenShift so the above changes to:

...
self.app = express();

self.app.configure(function() {
    self.app.use('/public', express.static(__dirname+'/public'));
    self.app.use('/graphql', GraphQL({
       schema: Schema,
       pretty: true,
       graphiql: true
    }));
});
...

But this doesn't work when pushed up to OpenShift. I get 'Internal Server Error' instead of the graphiql interface.

I'm new to this, but here are some guesses as to what it might have to do with:

  1. Connecting to database
  2. Missing dependencies

    1. Connecting to database: I have 2 json config files. One for my local machine which is connected using a port-forward SSH tunnel to OpenShift. That works fine. The other is one for production. In it I have all the strings for the database name, user, port, host, and password, that OpenShift provided me. I'm using the config library which looks at NODE_ENV to decide which config json file to use. I set the NODE_ENV variable on OpenShift to production. When I query it, it shows all the correct strings. Is there something else I need to set?

    2. Missing dependencies: To keep it neat, I am keeping my back-end code separate from my front-end code. So the back-end code has only the express, graphql, sequelize, config, and pg stuff installed. Do I need something else to make the graphiql page work? Also, I put all the /node_modules/ in the .gitignore file -- I assumed that OpenShift installs them post push. Was that the right thing to do?

Would appreciate any help!

Upvotes: 1

Views: 769

Answers (1)

Coco
Coco

Reputation: 1630

OK - I solved it by doing the following:

in the openshift cli tools turn on error logs

rhc tail -a <yourappname>

This will give you some clues. In my case it was a message from express-graphql "unresolved promise". After researching I found that if you install and save es-promise and add this line to the top of the server.js file:

require ('es6-promise').polyfill();

Hope that helps someone else!

Upvotes: 1

Related Questions