relay-tools / vscode-apollo-relay

Simple configuration of vscode-apollo for Relay projects.
MIT License
49 stars 13 forks source link

Extension broken on Apollo GraphQL v1.19.4 #34

Closed rrdelaney closed 2 years ago

rrdelaney commented 3 years ago

This (normally fantastic) library breaks with the newest release of the Apollo extension:

------------------------------
πŸš€ Apollo GraphQL v1.19.4
------------------------------
❌ Service stats could not be loaded. This may be because you're missing an apollo.config.js file or it is misconfigured. For more information about configuring Apollo projects, see the guide here (https://go.apollo.dev/t/config).

The root cause seems to be:

[ERROR] A config file failed to load with options: {"configPath":"/Users/ryan/Development/platform","requireConfig":true}.
    The error was: Error: Cannot find module 'apollo-language-server/lib/errors/validation'
Require stack:
- /Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/node_modules/import-fresh/index.js
- /Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/node_modules/cosmiconfig/dist/loaders.js
- /Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/node_modules/cosmiconfig/dist/createExplorer.js
- /Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/node_modules/cosmiconfig/dist/index.js
- /Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/lib/language-server/config/loadConfig.js
- /Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/lib/language-server/config/index.js
- /Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/lib/language-server/workspace.js
- /Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/lib/language-server/server.js
    at Object.loadConfig (/Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/lib/language-server/config/loadConfig.js:42:34)
    at async GraphQLWorkspace.reloadProjectForConfig (/Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/lib/language-server/workspace.js:107:22)
    at /Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/lib/extension.js:45:35
    at handleNotification (/Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/node_modules/vscode-jsonrpc/lib/main.js:489:43)
    at processMessageQueue (/Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/node_modules/vscode-jsonrpc/lib/main.js:260:17)
    at Immediate._onImmediate (/Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/node_modules/vscode-jsonrpc/lib/main.js:247:13)

From what I can tell this is because the Apollo extension no longer includes apollo-language-server as a dependency:

platform:main Ξ» ls ~/.vscode/extensions/apollographql.vscode-apollo-1.19.3/node_modules/apollo-language-server/
CHANGELOG.md         lib                  src                  tsconfig.test.json
__mocks__            package.json         tsconfig.json        tsconfig.tsbuildinfo
platform:main Ξ» ls ~/.vscode/extensions/apollographql.vscode-apollo-1.19.4/node_modules/apollo-language-server/
ls: /Users/ryan/.vscode/extensions/apollographql.vscode-apollo-1.19.4/node_modules/apollo-language-server/: No such file or directory
janicduplessis commented 3 years ago

@rrdelaney You are right, the extension no longer depends on apollo-language-server and the code in included in the extension package directly (https://github.com/apollographql/vscode-graphql/tree/main/src). I managed to get it working again with this patch.

diff --git a/node_modules/vscode-apollo-relay/dist/dependencies.js b/node_modules/vscode-apollo-relay/dist/dependencies.js
index 6bef19c..9b7ced4 100644
--- a/node_modules/vscode-apollo-relay/dist/dependencies.js
+++ b/node_modules/vscode-apollo-relay/dist/dependencies.js
@@ -7,16 +7,8 @@
 var _a;
 exports.__esModule = true;
 exports.RelayCompilerMain = exports.RelayConfig = exports.suggestionList = exports.didYouMean = exports.TypeInfo = exports.isInputType = exports.visitWithTypeInfo = exports.GraphQLObjectType = exports.GraphQLNonNull = exports.typeFromAST = exports.getNullableType = exports.isTypeSubTypeOf = exports.valueFromAST = exports.isNonNullType = exports.visit = exports.parseType = exports.GraphQLError = exports.BREAK = exports.defaultValidationRules = void 0;
-var mod = module;
-if (typeof jest === "undefined") {
-    while (mod && !mod.id.includes("apollographql.vscode-apollo")) {
-        mod = mod.parent;
-    }
-    if (mod === null) {
-        throw new Error("Unable to find vscode-apollo's node_modules");
-    }
-}
-exports.defaultValidationRules = mod.require("apollo-language-server/lib/errors/validation").defaultValidationRules;
+var mod = require.main;
+exports.defaultValidationRules = mod.require("./errors/validation").defaultValidationRules;
 exports.BREAK = (_a = mod.require("graphql"), _a.BREAK), exports.GraphQLError = _a.GraphQLError, exports.parseType = _a.parseType, exports.visit = _a.visit, exports.isNonNullType = _a.isNonNullType, exports.valueFromAST = _a.valueFromAST, exports.isTypeSubTypeOf = _a.isTypeSubTypeOf, exports.getNullableType = _a.getNullableType, exports.typeFromAST = _a.typeFromAST, exports.GraphQLNonNull = _a.GraphQLNonNull, exports.GraphQLObjectType = _a.GraphQLObjectType, exports.visitWithTypeInfo = _a.visitWithTypeInfo, exports.isInputType = _a.isInputType, exports.TypeInfo = _a.TypeInfo;
 exports.didYouMean = mod.require("graphql/jsutils/didYouMean")["default"];
 exports.suggestionList = mod.require("graphql/jsutils/suggestionList")["default"];

Not sure if this is a proper fix thought cc @alloy

natelindev commented 3 years ago

same for me

alloy commented 2 years ago

v1.5.2 has been published, thanks @erictaylor :pray:

rrdelaney commented 2 years ago

Can confirm this has fixed my project with the latest version of the Apollo extension πŸ˜„ Thank you so much!