File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -27,8 +27,9 @@ function expandImports(source, doc) {
2727 ` ;
2828
2929 lines . some ( ( line ) => {
30- if ( line [ 0 ] === '#' && line . slice ( 1 ) . split ( ' ' ) [ 0 ] === 'import' ) {
31- const importFile = line . slice ( 1 ) . split ( ' ' ) [ 1 ] ;
30+ const result = line . match ( / ^ # \s ? i m p o r t ( .+ ) $ / ) ;
31+ if ( result ) {
32+ const importFile = result [ 1 ] ;
3233 const parseDocument = `require(${ importFile } )` ;
3334 const appendDef = `doc.definitions = doc.definitions.concat(unique(${ parseDocument } .definitions));` ;
3435 outputCode += appendDef + os . EOL ;
Original file line number Diff line number Diff line change @@ -236,6 +236,31 @@ describe('gql', () => {
236236 assert . equal ( definitions [ 1 ] . kind , 'FragmentDefinition' ) ;
237237 } ) ;
238238
239+ it ( 'importing files also works with a space between `#` and `import`' , ( ) => {
240+ const query = `# import "./fragment_definition.graphql"
241+ query {
242+ author {
243+ ...authorDetails
244+ }
245+ }` ;
246+ const jsSource = loader . call ( { cacheable ( ) { } } , query ) ;
247+ const module = { exports : Object . create ( null ) } ;
248+ const require = ( path : string ) => {
249+ assert . equal ( path , './fragment_definition.graphql' ) ;
250+ return gql `
251+ fragment authorDetails on Author {
252+ firstName
253+ lastName
254+ }` ;
255+ } ;
256+ Function ( "module,require" , jsSource ) ( module , require ) ;
257+ assert . equal ( module . exports . kind , 'Document' ) ;
258+ const definitions = module . exports . definitions ;
259+ assert . equal ( definitions . length , 2 ) ;
260+ assert . equal ( definitions [ 0 ] . kind , 'OperationDefinition' ) ;
261+ assert . equal ( definitions [ 1 ] . kind , 'FragmentDefinition' ) ;
262+ } ) ;
263+
239264 it ( 'tracks fragment dependencies across fragments loaded via the webpack loader' , ( ) => {
240265 const query = `#import "./fragment_definition.graphql"
241266 fragment F111 on F {
You can’t perform that action at this time.
0 commit comments