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.

`possible-type-extension` erroring when extending types defined in separate files.

See original GitHub issue

Describe the bug

possible-type-extension erroring when extending types defined in separate files.

Error:

Cannot extend type "Query" because it is not defined  @graphql-eslint/possible-type-extension

Additionally, if this error triggers for any file, an error shows up in lint results for every file in which a type was extended. Also, I notice messaging is slightly different when extending known types likeQuery vs custom types like NotQuery.

To Reproduce Steps to reproduce the behavior:

Run yarn lint in below repo. https://github.com/JustinTRoss/graphql-eslint-issue-repro

Expected behavior

Ideally, no errors would be thrown when extending a type defined in another file.

Environment:

  • OS: MacOS 11.4
  • @graphql-eslint/...: 2.5
  • NodeJS: 14.17.5

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
B2o5Tcommented, Jan 1, 2022

You’re quick! Those two scenarios look mitigated. I come bearing another 🙌 . 😛

If you define a duplicate version of the same type with violations in it, like duplicate conflicting fields, depending the order of loaded files, it will report either as an error merging types or an error defining type. At the same time, it errors out and inaccurately conveys that the eslint parserOptions.schema is not set, but is required for the possible-type-extension rule.

Try running yarn lint on this branch.

Offending type/field def here.

this is expected behavior, we can’t build a schema that contains validation errors like duplicated fields, in this case, we aren’t able to provide a GraphQL schema for rules that require it.

Possibly getting away from the scope of this rule and the changes made here, but I found I could invalidly define a union and extend it without any issue.

See this branch for details.

Fixed in 3.4.0-alpha-735b6ae.0. Please not you’ll get an erroneous possible-type-extension error in another file because the error Union type ... can only include ... goes from validate() function and not from possible-type-extension rule.

/Users/dimitri/Desktop/graphql-eslint-issue-repro/src/index.ts
  5:1  error  Union type Product can only include Object types, it cannot include Genre  @graphql-eslint/possible-type-extension

/Users/dimitri/Desktop/graphql-eslint-issue-repro/src/modules/Schema/first/firstSchema.ts
  3:1  error  Union type Product can only include Object types, it cannot include Genre  @graphql-eslint/possible-type-extension

/Users/dimitri/Desktop/graphql-eslint-issue-repro/src/modules/Schema/second/secondSchema.ts
  3:1  error  Union type Product can only include Object types, it cannot include Genre  @graphql-eslint/possible-type-extension

✖ 3 problems (3 errors, 0 warnings)

Further, if I defined union in certain invalid ways, it errors regarding merging of unrelated valid types in a different file.

See this branch for details.

It’s related to how graphql validate SDL, I can’t do anything here

2reactions
JustinTRosscommented, Dec 28, 2021

You’re quick! Those two scenarios look mitigated. I come bearing another 🙌 . 😛

If you define a duplicate version of the same type with violations in it, like duplicate conflicting fields, depending the order of loaded files, it will report either as an error merging types or an error defining type. At the same time, it errors out and inaccurately conveys that the eslint parserOptions.schema is not set, but is required for the possible-type-extension rule.

Try running yarn lint on this branch.

Offending type/field def here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[SR-631] Extensions in different files do not recognize ... - GitHub
SR-4568 Extension of a nested type defined in a separate source file fails to compile; SR-4798 Trying to extend a subclass defined in...
Read more >
How do I extend a TypeScript class definition in a separate ...
I wish to use a plugin which extends some of the objects in leaflet with an extra function. In the existing TypeScript definition...
Read more >
Extending various TypeScript type declarations
Extending types of a 3rd party library is usually no different than extending any global type declaration. The three-step process defined in the ......
Read more >
Extending object-like types with interfaces in TypeScript
Extending object-like types with interfaces in TypeScript · Option 1: Declaration merging · Declaration merging to wrangle disparate user ...
Read more >
Extension Types — Cython 3.0.0a11 documentation
If the base type is defined in another Cython module, it must either be declared as an extern extension type or imported using...
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