all files / semantic-graphql/src/ requireGraphqlRelay.js

21.43% Statements 3/14
0% Branches 0/8
0% Functions 0/1
25% Lines 3/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                                                
let graphqlRelay;
 
// optionalPeerDependencies still don't exist, so graphql-relay is a ghost dep
// let's find it
function requireGraphqlRelay() {
  if (graphqlRelay) return graphqlRelay;
 
  try {
    graphqlRelay = require('graphql-relay');
  }
  catch (ex) {
    // Nothing
  }
 
  if (!graphqlRelay) {
    // Go up until graphql-relay is found
    // Inspired by https://www.npmjs.com/package/parent-require
    for (let parent = module.parent; parent && !graphqlRelay; parent = parent.parent) {
      try {
        graphqlRelay = parent.require('graphql-relay');
      }
      catch (ex) {
        // Nothing
      }
    }
 
    // No pity
    if (!graphqlRelay) throw new Error('semantic-graphql was not able to find "graphql-relay" as a dependency of your project. Run "npm install graphql-relay" or set the "relay" option to false.');
  }
 
  return graphqlRelay;
}
 
module.exports = requireGraphqlRelay;