@@ -2,6 +2,8 @@ import globby, { sync as globbySync, GlobbyOptions } from 'globby';
2
2
import unixify from 'unixify' ;
3
3
import { extname } from 'path' ;
4
4
import { statSync , readFileSync , promises as fsPromises } from 'fs' ;
5
+ import { DocumentNode } from '@apollo/client/core' ;
6
+ import { parse } from 'graphql' ;
5
7
6
8
const { readFile, stat } = fsPromises ;
7
9
@@ -157,7 +159,8 @@ export function loadFilesSync<T = any>(
157
159
const extractedExport = extractExports ( fileExports ) ;
158
160
return extractedExport ;
159
161
} else {
160
- return readFileSync ( path , { encoding : 'utf-8' } ) ;
162
+ const maybeSDL = readFileSync ( path , { encoding : 'utf-8' } ) ;
163
+ return tryToParse ( maybeSDL ) ;
161
164
}
162
165
} )
163
166
. filter ( v => v ) ;
@@ -237,7 +240,8 @@ export async function loadFiles(
237
240
const extractedExport = extractExports ( fileExports ) ;
238
241
return extractedExport ;
239
242
} else {
240
- return readFile ( path , { encoding : 'utf-8' } ) ;
243
+ const maybeSDL = await readFile ( path , { encoding : 'utf-8' } ) ;
244
+ return tryToParse ( maybeSDL ) ;
241
245
}
242
246
} )
243
247
) ;
@@ -247,3 +251,11 @@ function isIndex(path: string, extensions: string[] = []): boolean {
247
251
const IS_INDEX = / ( \/ | \\ ) i n d e x \. [ ^ \/ \\ ] + $ / i; // (/ or \) AND `index.` AND (everything except \ and /)(end of line)
248
252
return IS_INDEX . test ( path ) && extensions . some ( ext => path . endsWith ( formatExtension ( ext ) ) ) ;
249
253
}
254
+
255
+ function tryToParse ( maybeSDL : string ) : string | DocumentNode {
256
+ try {
257
+ return parse ( maybeSDL ) ;
258
+ } catch ( e ) {
259
+ return maybeSDL ;
260
+ }
261
+ }
1 commit comments
vercel[bot] commentedon Sep 29, 2021
Successfully deployed to the following URLs: