Mayank1791989 / gql

112 stars 19 forks source link

getSchemaErrors returns undefined #188

Open Cellule opened 3 years ago

Cellule commented 3 years ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch @playlyfe/gql@2.6.2 for the project I'm working on.

I didn't dig deeper, but I got an error very early when using vs code extension graphql-for-vscode which uses this project. From what I can tell if getSchemaErrors is called before _updateFiles in GQLSchemaBuilder it could lead to _errors to be undefined.

Here is the diff that solved my problem:

diff --git a/node_modules/@playlyfe/gql/lib/GQLService.js b/node_modules/@playlyfe/gql/lib/GQLService.js
index ed4507e..31ee161 100644
--- a/node_modules/@playlyfe/gql/lib/GQLService.js
+++ b/node_modules/@playlyfe/gql/lib/GQLService.js
@@ -117,7 +117,7 @@ var GQLService = exports.GQLService = function () {
       if (!this._isInitialized) {
         return [];
       }
-      var schemaErrors = this._schemaBuilder.getSchemaErrors();
+      var schemaErrors = this._schemaBuilder.getSchemaErrors() || [];
       var queryErrors = this._queryManager ? this._queryManager.getErrors() : [];
       return schemaErrors.concat(queryErrors.filter(function (err) {
         return Boolean(err);

This issue body was partially generated by patch-package.