question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect behaviour with operations in .js/.ts files

See original GitHub issue

Describe the bug The @graphql-eslint/unique-fragment-name, @graphql-eslint/unique-operation-name, and @graphql-eslint/known-fragment-names rules seem to incorrectly report errors when operations are defined in .js/.ts files.

To Reproduce Steps to reproduce the behavior:

https://github.com/mikew/graphql-eslint-woes

Expected behavior There should be no issues in the repo above.

Environment:

  • OS: macOS
  • @graphql-eslint/...: latest
  • NodeJS: 14

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
B2o5Tcommented, Jul 5, 2021

The false positive issue with known-fragment-names - currently it’s not possible to handle string interpolation because graphql-tag-pluck doesn’t support it (we use graphql-tag-pluck under the hood for extract documents from js/ts files)

And the issue with unique-fragment-name and unique-operation-name I’ll fix this week

2reactions
dotansimhacommented, Jul 4, 2021

Thanks for looking into this so quickly! Curious, what about the loadSiblings snippet above seems strange?

We have 3 different kinds of files loaded in this plugin:

  1. Regular .graphql file - loaded with ESLint core using the plugin, and then we parse it with GraphQL and convert it to ESTree.
  2. Code files with GraphQL code - we call these “virtual files” since we use ESLint processor to extract these from JS/TS files, and then we can a virtual file path (that doesn’t exists in FS).
  3. Siblings - these are operations loaded as “siblings” to either regular file or virtual files, and they are in use in order to support or enrich the plugins with more info (For example, you might use ESLint for lining a GraphQL file with a query, but if that query is using a fragment spread, we have a mechanism that loads the fragment)

The snippet @B2o5T mentioned is the one that compares file paths while loading siblings. When it’s loaded against while linting a virtual file, we probably compare it in the wrong way (maybe we should use the original file path, not the virtual?).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Type Checking JavaScript Files - TypeScript
In a .js file, the compiler infers properties from property assignments inside the class body. The type of a property is the type...
Read more >
Configuration For Treating JS/TS Files as Independent Units ...
Actual behavior: The files are treated as a single unit. foo either has a string or number type in both files.
Read more >
The 10 Most Common JavaScript Issues Developers Face
JavaScript Issue #1: Incorrect References to this. There's no shortage of confusion among JavaScript developers regarding JavaScript's this keyword.
Read more >
JavaScript .JS file is not included or nested under my ...
I am running Visual Studio 2017, and I have a fine Typescript .TS file. I have made the following very advanced Typescript code:...
Read more >
PhpStorm - Code Inspections in JavaScript and TypeScript
Inaccurate platform detection. Reports a common JavaScript pattern for detecting the browser or operating system in which the script is run.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found