graphiql icon indicating copy to clipboard operation
graphiql copied to clipboard

Decorators break completion

Open sdykae opened this issue 2 years ago • 11 comments

Actual Behavior

image

Expected Behavior

image

Steps to Reproduce the Problem Or Description

image

Specifications

  • GraphQL for VSCode Extension Version: 0.3.18

  • VSCode Version: latest

  • OS Name: linux

  • OS Version: ubuntu 20.04

#fix
https://github.com/babel/babel-eslint/issues/774 https://github.com/babel/babel-eslint/issues/662 https://stackoverflow.com/questions/53483066/babel-7-using-the-export-keyword-between-a-decorator-and-a-class-is-not-allowed/54516632

Why babel-eslint is triggered? Wtf? My project don't use babel, or eslint.

sdykae avatar Nov 11 '21 07:11 sdykae

we use babel in the language server for parsing javascript and typescript, and finding tags

there is a known bug where decorators break the language server

acao avatar Nov 11 '21 16:11 acao

Is there a way to pass those options

parserOptions: { ecmaVersion: 2015, ecmaFeatures: { legacyDecorators: true } }

to fix it? @acao

sdykae avatar Nov 11 '21 16:11 sdykae

This is bugging me for months now. It's so annoying to comment out/in the decorators just so the autocomplete works.

tfp avatar Dec 06 '21 14:12 tfp

Bugging me as well. Breaks autocomplete for all my angular services

JonatanE avatar Jan 12 '22 10:01 JonatanE

Affect my nestjs project as well.

fajarclodeo avatar May 25 '22 02:05 fajarclodeo

Any update on this issue ?

acivier-serial avatar Jul 14 '22 08:07 acivier-serial

I’m in the midst of a big project at work, but if someone wants to open a PR with those changes to the babel parser options and a test for findGraphQLTags that proves the fix, it would be very welcome!

acao avatar Jul 14 '22 09:07 acao

At this service level (@babel/parser) we have decorators-legacy available, however I get this error whenever we execute parse() on any file in the language server:

Screenshot 2022-07-16 at 01 21 56

we can add an option to allow someone to optionally enable support for decorators-legacy, which would disable support for decorators? one could use projects to filter which files have this setting enabled?

acao avatar Jul 15 '22 23:07 acao

https://github.com/graphql/graphiql/blob/48e7710a80739931565e1d472ed38136cc73865f/packages/graphql-language-service-server/src/findGraphQLTags.ts#L43

joepjoosten avatar Aug 09 '22 12:08 joepjoosten

any updates on this. is there a way just to block it looking at the typescript with decorators, we are currently running a monorepo with the graph queries defined in a react app and a nest server. The nest server doesn't need any graph queries but because it has decorators its breaking the rest of the thing..

jrwpatterson avatar Aug 23 '22 21:08 jrwpatterson

If someone wants to open a PR it’s a relatively simple option to add opt in for legacy decorators. We can’t just enable support for legacy decorators, because then it would break the working support for decorators

acao avatar Aug 24 '22 05:08 acao

@acao I've added the changes in this fork: https://github.com/mvnrhd/graphiql/tree/feat/add-opt-in-for-legacy-decorators. Unfortunately, I didn't manage to fully test my changes locally and tests are missing as well. But maybe you (or someone else) could use it as a basis for addressing the issue soon? 🚀

mvnrhd avatar Oct 07 '22 08:10 mvnrhd

@mvnrhd indeed, happy to do that! Thank you!

acao avatar Oct 15 '22 16:10 acao

Hey @acao, do you think you could tackle this soon? 🙂

mvnrhd avatar Oct 29 '22 11:10 mvnrhd

@mvnrhd hey this is awesome, thank you! finally had a chance to take a look

The only thing is that it's a vscode setting only, with no graphql-config options yet -

This means non-vscode users might have more trouble opting in to this feature - for example most nvim coc users just configure the graphql config for the LSP server, and aren't used to needing to set extension settings.

It also means you can't have it enabled for a single project, and disabled for others - it's all or nothing.

We just need to support this config coming from the matching graphql-config project or vscode settings. Do you think you can add that to the branch? I see this bug has 9 watchers which means it's one of our top priority bugs with the LSP - this is the one that blocks nest.js and others yes?

acao avatar Oct 31 '22 07:10 acao

so here, we need to retrieve the project from the URI, and decide whether to use legacy decorators or not for the project for that URI

Screenshot 2022-10-31 at 09 02 10

For example, we use this approach to allow you to configure whether you want validation enabled on a per-project basis

https://github.com/graphql/graphiql/compare/main...mvnrhd:graphiql:feat/add-opt-in-for-legacy-decorators#diff-7757a3768d45bacff6ba6fdef1dd9aff1b7174c99f2bdac30374d0129ad69f09L377

acao avatar Oct 31 '22 08:10 acao

Thanks for the implementation hints @acao. Since I'm quite busy atm not sure if I can make it this week. Sounds straightforward though.

mvnrhd avatar Nov 02 '22 13:11 mvnrhd

@acao I've incorporated your suggestions in commit https://github.com/graphql/graphiql/commit/02923a5cb39f4eb59b3c955e350ad34992a3e410. Hope that covers the use case you've mentioned. 🙏

mvnrhd avatar Nov 10 '22 15:11 mvnrhd

Thanks for this @mvnrhd! Almost feels excessive in retrospect. I've been thinking about this fix for a long time, making it happen tonight! Sorry it's been so long everyone

acao avatar Nov 10 '22 23:11 acao

After finally writing some unit tests, from what I can tell, enabling decorators-legacy actually allows both legacy es7 decorators syntax and the current syntax. I will leave decorators-legacy enabled instead of decorators because it's less restrictive, and decorators offers nothing new.

acao avatar Nov 12 '22 14:11 acao

the latest [email protected] and related lsp server version should fix this! thanks everyone

acao avatar Nov 12 '22 16:11 acao