facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.41k stars 1.83k forks source link

Relay Resolver has module resolution problem in TypeScript #3989

Closed ellemedit closed 2 years ago

ellemedit commented 2 years ago
Screen Shot 2022-06-22 at 15 34 22 Screen Shot 2022-06-22 at 15 37 58

As above images, generated relay artifacts import relay resolver with extension. I think using ".js" extension or skipping extension are correct solution at this moment. So we can inference return type of RelayResolver function in TypeScript.

alunyov commented 2 years ago

The Relay Resolvers is still in active development, and typescript support maybe lacking in some places. Thanks for reporting!

captbaritone commented 2 years ago

Thanks for the report @Beingbook. If you're interested in working on a fix, I suspect stripping the extension would be the right approach and the I think the code that derives this path lives here: https://github.com/facebook/relay/blob/main/compiler/crates/relay-config/src/project_config.rs#L360

cc @tbezman

ellemedit commented 2 years ago

oops, I'm too late. thank you for suggesting contribution! I want to work if there's next time.

chriserickson commented 2 years ago

This was not fixed in 14.1 - the dynamic imports in the AST omit extensions, however the type imports still have the extensions.

It appears that https://github.com/facebook/relay/blob/639abe1b23ed2187500514c331bed3aebede2f02/compiler/crates/relay-typegen/src/typescript.rs#L97 and https://github.com/facebook/relay/blob/639abe1b23ed2187500514c331bed3aebede2f02/compiler/crates/relay-typegen/src/typescript.rs#L101

Both also need to strip extensions, as typescript requires that extensions not be provided.

Is it possible to re-open this? I'm happy to work on a fix.

chriserickson commented 2 years ago

I went ahead and created a new issue:

https://github.com/facebook/relay/issues/4056