diff --git a/src/rule-must-colocate-fragment-spreads.js b/src/rule-must-colocate-fragment-spreads.js index b13a14b..f92cd95 100644 --- a/src/rule-must-colocate-fragment-spreads.js +++ b/src/rule-must-colocate-fragment-spreads.js @@ -134,8 +134,8 @@ module.exports = { graphqlLiterals.forEach(({node, graphQLAst}) => { const queriedFragments = getGraphQLFragmentSpreads(graphQLAst); for (const fragment in queriedFragments) { - const matchedModuleName = foundImportedModules.find(name => - fragment.startsWith(name) + const matchedModuleName = foundImportedModules.find( + name => name && fragment.startsWith(name) ); if ( !matchedModuleName && diff --git a/test/must-colocate-fragment-spreads.js b/test/must-colocate-fragment-spreads.js index db6f30d..1b89da4 100644 --- a/test/must-colocate-fragment-spreads.js +++ b/test/must-colocate-fragment-spreads.js @@ -108,6 +108,14 @@ ruleTester.run( # eslint-disable-next-line relay/must-colocate-fragment-spreads ...unused1 }\`; + `, + ` + import { foo } from '../'; + import { Component } from '../shared/component.js'; + console.log(foo); + graphql\`fragment foo on Page { + ...component_fragment + }\`; ` ], invalid: [