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

Missing TS type definition for relay config #4348

Open
MarceloPrado opened this issue Jun 17, 2023 · 8 comments
Open

Missing TS type definition for relay config #4348

MarceloPrado opened this issue Jun 17, 2023 · 8 comments

Comments

@MarceloPrado
Copy link

Jest offer users typed definitions for their config files:

/** @type {import('jest').Config} */
const config = {
  verbose: true,
};

module.exports = config;

As explained in their docs, you can write your docs in JS and use JSDocs to get type inference. Another approach is to write the config file in TS and directly import the Config type.

Would the Relay team consider offering something similar? It would improve the DX when configuring the compiler. The current approach requires me to open the relay-compiler README to manually ensure I'm using the right options.

@maraisr
Copy link
Contributor

maraisr commented Jun 19, 2023

We did have a contribution to our types to add this, but was abandoned.

I'll raise a PR to fix this. Sorry about that, that PR snuck through and didnt notice.

Wondering though, would you @captbaritone be open to have this config file included in the relay-compiler package, or keep things over at DT for now?

@captbaritone
Copy link
Contributor

I love the idea, and this is something I would love for us to have. That said, I think there is at least one questions we should answer first:

How can we ensure the types file gets updated every time the compiler itself gets updated?

@maraisr
Copy link
Contributor

maraisr commented Jun 19, 2023

Yeah I think there is a bigger story here with typescript in general, but at least for today — perhaps we can use the existing config types to codegen the typescript types? If you have ideas, happy yo PoC it.

@EloB
Copy link

EloB commented Jul 25, 2023

To his two flies in one hit than also upload a JSON schema to https://www.schemastore.org/json/ to make VSCode and a bunch of editors autocomplete it. Maybe promote a name for that json config like relay.config.json or something.

@alecmev
Copy link

alecmev commented Jul 24, 2024

It's not released yet, but there's a schema now, added in #4723:

{
  "$schema": "https://github.com/facebook/relay/raw/9f314a080274960ccd9257b66c47b3c6f3d74956/compiler/relay-compiler-config-schema.json",
  // ...
}

Never mind, the above currently crashes with unknown field $schema.

It's released, and it works, and you can also do this:

{
  "$schema": "./node_modules/relay-compiler/relay-compiler-config-schema.json",
  // ...
}

@MarceloPrado
Copy link
Author

Fixed by #4724

@tobias-tengler
Copy link
Contributor

The original issue isn't really solved though, right? You now have support for JSON files, but if you're using the JS config loader you still don't have any TypeScript types (unless you generate them yourself based on the JSON schema)

@MarceloPrado
Copy link
Author

@tobias-tengler you're right, sorry for closing this. It still makes sense to provide something at the Relay land for JS configs.

@MarceloPrado MarceloPrado reopened this Oct 17, 2024
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

No branches or pull requests

6 participants