Separate GraphQL schema from implementation

A common yet unwise practice is to extensively use graphql-js ‘s constructors like GraphQLObjectType , GraphQLSchema , GraphQLString or else. However, this is a bad design since GraphQL API is not separated from JavaScript implementation. In other words, if a frontend developer wants to have a look at the backend API, s/he has to step into gateway source code, which is written in backend-JavaScript (or even worse, Python or Ruby or something totally different from frontend-JavaScript).

See which of the following is more abstract and friendlier for a frontend developer.

Thankfully, package graphql-tools provides an awesome function called makeExecutableSchema . You may wish to have a look at its API before moving on.

The following code snippet is an example of how to use it with separate GraphQL schema file. You may wish to replace fs.readFileSync with fs.readFile to accelerate start-up.