Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[apollo-graphql] vscode gql tag functionality broken when relative globs used in includes config #1002

Closed
warmbowski opened this issue Feb 9, 2019 · 3 comments · Fixed by #1007

Comments

@warmbowski
Copy link

Auto-complete and type hints do not work in gql tagged template literals when the includes config setting in apollo.config.js file has relative globs in it (globs that start with ./). Some of this is documented in issue #690.

Intended outcome:

When I set my includes glob to includes: ['./examples/**/*.{ts,tsx}'], I expect that project files with gql tagged template literals that match that glob work with apollo-graphql extension auto-complete and type hint hover functionality in the graphql query. And when clicking the status bar ApolloGraphQL button when in a file that matches the glob, a status message similar to below is displayed.

------------------------------
🚀 Apollo GraphQL v1.4.5
------------------------------
✅ Service Loaded!
🆔 Service ID: OSTK GraphQL Demo1
🏷 Schema Tag: current
📈 Number of Types: 45 (0 client types)
------------------------------

Actual outcome:

apollo-graphql extension functionality doesn't work in vscode. There are no type hints or auto-complete based on schema. Moreover, when clicking the status bar ApolloGraphQL button when in a file other than apollo.config.js the error message below is shown in the OUTPUT panel.

------------------------------
🚀 Apollo GraphQL v1.4.5
------------------------------
❌ 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://bit.ly/2ByILPj).

Changing the includes config to includes: ['examples/**/*.{ts,tsx}'], (relative but without ./ at the beginning) makes it work as expected.

How to reproduce the issue:
Open an apollo-graphql based project that has client.service.localSchemaFile, client.service.url, or apollo engine set up and working properly. Set up a folder outside of the src/ folder (this should skirt the default includes - in my case it was examples/) with a component the uses a gql tagged template literal. Try different includes config setting with and without ./ at the beginning to see the difference in behaviour

Versions
apollo@2.4.4
vscode@1.31.0
apollo-graphql@1.4.5

@warmbowski
Copy link
Author

warmbowski commented Feb 9, 2019

https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo-language-server/src/fileSet.ts#L34

minimatch() seems to be the culprit here. It doesn't want to treat relative globs with and without starting ./ the same when it makes the matches. Unlike glob.sync() (in the allFiles method) which captures the same set of files with using either syntax for the relative glob.

My suggestion for an improved version of the includesFile method that is consistent in treating the two relative globs the same is:

includesFile(filePath) {
    return this.allFiles().includes(filePath);
};

Basically, it's relying on glob.sync() output and matching within. I am not sure what the performance implications are. I think it could be bad with lots of files.

@warmbowski
Copy link
Author

I was using the code in this gist (running on node 8) to investigate what's going on.
https://gist.github.com/warmbowski/dde917a43b925a5dec41ef5cde8d29fc

@trevor-scheer
Copy link
Member

This is excellent, thank you for opening this issue and giving some background 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants