@@ -4,44 +4,38 @@ import debugFactory from 'debug';
44import { convertToESTree , extractComments , extractTokens } from './estree-converter' ;
55import { GraphQLESLintParseResult , ParserOptions } from './types' ;
66import { getSchema } from './schema' ;
7- import { getSiblingOperations } from './sibling-operations ' ;
7+ import { getDocuments } from './documents ' ;
88import { loadGraphQLConfig } from './graphql-config' ;
9- import { getOnDiskFilepath } from './utils' ;
9+ import { CWD , VIRTUAL_DOCUMENT_REGEX } from './utils' ;
1010
1111const debug = debugFactory ( 'graphql-eslint:parser' ) ;
1212
13- debug ( 'cwd %o' , process . cwd ( ) ) ;
13+ debug ( 'cwd %o' , CWD ) ;
1414
1515export function parseForESLint ( code : string , options : ParserOptions ) : GraphQLESLintParseResult {
1616 try {
1717 const { filePath } = options ;
18- const realFilepath = getOnDiskFilepath ( filePath ) ;
19-
20- const gqlConfig = loadGraphQLConfig ( options ) ;
21- const projectForFile = realFilepath
22- ? gqlConfig . getProjectForFile ( realFilepath )
23- : gqlConfig . getDefault ( ) ;
24-
25- const schema = getSchema ( projectForFile , options ) ;
26- const siblingOperations = getSiblingOperations ( projectForFile ) ;
27-
18+ // First parse code from file, in case of syntax error do not try load schema,
19+ // documents or even graphql-config instance
2820 const { document } = parseGraphQLSDL ( filePath , code , {
2921 ...options . graphQLParserOptions ,
3022 noLocation : false ,
3123 } ) ;
24+ const gqlConfig = loadGraphQLConfig ( options ) ;
25+ const realFilepath = filePath . replace ( VIRTUAL_DOCUMENT_REGEX , '' ) ;
26+ const project = gqlConfig . getProjectForFile ( realFilepath ) ;
3227
33- const comments = extractComments ( document . loc ) ;
34- const tokens = extractTokens ( filePath , code ) ;
28+ const schema = getSchema ( project , options . schemaOptions ) ;
3529 const rootTree = convertToESTree ( document , schema instanceof GraphQLSchema ? schema : null ) ;
3630
3731 return {
3832 services : {
3933 schema,
40- siblingOperations,
34+ siblingOperations : getDocuments ( project ) ,
4135 } ,
4236 ast : {
43- comments,
44- tokens,
37+ comments : extractComments ( document . loc ) ,
38+ tokens : extractTokens ( filePath , code ) ,
4539 loc : rootTree . loc ,
4640 range : rootTree . range as [ number , number ] ,
4741 type : 'Program' ,
0 commit comments