diff --git a/packages/graphql/lib/util.js b/packages/graphql/lib/util.js index 5364cf513..3f07bd681 100644 --- a/packages/graphql/lib/util.js +++ b/packages/graphql/lib/util.js @@ -7,3 +7,11 @@ var hopsConfig = require('hops-config'); exports.getFragmentsFile = function getFragmentsFile () { return path.join(hopsConfig.appDir, 'fragmentTypes.json'); }; + +exports.getIntrospectionResult = function getIntrospectionResult () { + var file = exports.getFragmentsFile(); + try { + require.resolve(file); + return require(file); + } catch (_) {} +}; diff --git a/packages/graphql/node.js b/packages/graphql/node.js index eac9922df..620d975ea 100644 --- a/packages/graphql/node.js +++ b/packages/graphql/node.js @@ -1,11 +1,9 @@ 'use strict'; -var fs = require('fs'); - var ReactApollo = require('react-apollo'); var common = require('./lib/common'); -var fragmentsFile = require('./lib/util').getFragmentsFile(); +var introspectionResult = require('./lib/util').getIntrospectionResult(); exports.Context = exports.createContext = common.Context.extend({ prepareRender: function (enhancedElement) { @@ -16,9 +14,7 @@ exports.Context = exports.createContext = common.Context.extend({ return common.Context.prototype.createClient.call(this, options); }, getIntrospectionResult: function () { - if (fs.existsSync(fragmentsFile)) { - return require(fragmentsFile); - } + return introspectionResult; }, getTemplateData: function () { var templateData = common.Context.prototype.getTemplateData.call(this);