graphql / graphiql

GraphiQL & the GraphQL LSP Reference Ecosystem for building browser & IDE tools.
MIT License
15.97k stars 1.72k forks source link

[lsp-server] 🐞 LSP crash on multi-root mono-repo when schema file contains error. #3435

Open charleslai2000 opened 11 months ago

charleslai2000 commented 11 months ago

Is there an existing issue for this?

Current Behavior

LSP crash when schema file contains error in multi-project monorepo.

/home/charles/.vscode-server/extensions/graphql.vscode-graphql-0.8.19/out/server/index.js:4640
 '${t.documents}'`),this._logger.error(String(r))}}async _cacheAllProjectFiles(t){if(t?.projects)return Promise.all(Object.keys(t.projects).map(async r=>{let n=t.getProject(r);await this._cacheSchemaFilesForProject(n),await this._cacheDocumentFilesforProject(n)}))}_isRelayCompatMode(t){return t.includes("RelayCompat")||t.includes("react-relay/compat")}async _updateFragmentDefinition(t,r){let n=this._graphQLCache.getGraphQLConfig().dirpath;await this._graphQLCache.updateFragmentDefinition(n,t,r)}async _updateSchemaIfChanged(t,r){await Promise.all(this._unwrapProjectSchema(t).map(async n=>{let i=Dx.resolve(t.dirpath,n);uV.URI.parse(r).fsPath===i&&await this._graphQLCache.invalidateSchemaCacheForProject(t)}))}_unwrapProjectSchema(t){let r=t.schema,n=[];if(typeof r=="string")n.push(r);else if(Array.isArray(r))for(let i of r)typeof i=="string"?n.push(i):i&&n.push(...Object.keys(i));else {console.log(r);n.push(...Object.keys(r))};return n}async _updateObjectTypeDefinition(t,r){let n=this._graphQLCache.getGraphQLConfig().dirpath;await this._graphQLCache.updateObjectTypeDefinition(n,t,r)}_getCachedDocument(t){if(this._textDocumentCache.has(t)){let r=this._textDocumentCache.get(t);if(r)return r}return null}async _invalidateCache(t,r,n){var i;if(this._textDocumentCache.has(r)){let a=this._textDocumentCache.get(r);if(a&&t&&t?.version&&a.version<t.version)return this._textDocumentCache.set(r,{version:t.version,contents:n})}return this._textDocumentCache.set(r,{version:(i=t.version)!==null&&i!==void 0?i:0,contents:n})}};kx.MessageProcessor=QGe;function YGe(e,t,r){let n=t.split(`
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at QGe._unwrapProjectSchema (/home/charles/.vscode-server/extensions/graphql.vscode-graphql-0.8.19/out/server/index.js:4640:929)
    at QGe._updateSchemaIfChanged (/home/charles/.vscode-server/extensions/graphql.vscode-graphql-0.8.19/out/server/index.js:4640:558)
    at /home/charles/.vscode-server/extensions/graphql.vscode-graphql-0.8.19/out/server/index.js:4635:5335
    at async Promise.all (index 0)

Expected Behavior

Act as normal.

Steps To Reproduce

Insert some error in schema file and save.

Error occurs when projectSchema is undefined. But I have an array of schema in .graphqlrc.

Environment

Anything else?

No response

charleslai2000 commented 11 months ago

I try to change the code to avoid crash, syntax highlighting and outline is OK, but symbol jump, cache file generation fail.

charleslai2000 commented 11 months ago

I have found the reason, it is caused by some bug in graphql-config, when provide configuration with schema, includes, graphql-config wil treat this configuration as legacy mode and try to read schema entries in schemaPath field, and return undefined in this case.