-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Generate JSON schema for compiler config #4723
Conversation
Love the resumed work on this! I updated my old attempt to your version in #4724 |
Oh this is great! I wasn't sure if there was a way for the VSCode extension to locate the Json Schema file in node_modules. Looking forward to looking more closely at that PR. Also, my sincere apologies for not acknowledging previous attempts at this. I had forgotten about your PR and also @tbezman! I've updated the description to reference both. |
Add json schema for savedStateConfig Don't remove deprecated config options. Do that in separate PR
e7e0561
to
eb29575
Compare
@@ -360,6 +360,13 @@ const relayCompiler = gulp.parallel( | |||
}) | |||
.pipe(gulp.dest(path.join(DIST, 'relay-compiler'))); | |||
}, | |||
function copyCompilerConfigSchema() { | |||
return gulp | |||
.src(['relay-compiler-config-schema.json'], { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tobias-tengler This should put the config schema in the root of the relay-compiler
npm module.
let expected_file_path = workspace_root() | ||
.join(source_file_path) | ||
.with_file_name("../../../relay-compiler-config-schema.json"); | ||
assert_file_contains(&actual, expected_file_path, expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reuses some of the logic from our fixture files:
- It will fail and show a diff if the current file does not match
- Setting
UPDATE_SNAPSHOTS=1
will cause it to update the file
@captbaritone has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Is pretty easy to solve, send a PR to https://github.com/SchemaStore/schemastore/blob/master/src/api/json/catalog.json with a link to a version you host on the relay website |
@orta Neat! How does version resolution work? If we add multiple versions there, who choses which one to use? |
@captbaritone merged this pull request in f544585. |
It basically doesn't - I think? Might be able to do it with more control if you used the vscode extension to set the schema instead probably |
Yeah, that's what I think we'll do. Tobias already has a PR open. |
One huge usability issue with Relay today is that the compiler config is wholely undocumented. To understand what options are available you either need to try an option and try to decipher the sometime cryptic validation errors, or read the Rust code.
This PR attempts to start to close that gap. Our Rust structs and comments are a good source of truth for this info, so ideally we still use that as our documentation/validation. So, here we derive Json Schema from our Rust structs/enums/types/serde tags.
In VSCode this allows for nice autocomplete, hover tool tips, and yellow squiggles if you make an error (much nicer than a cryptic validation error when you run the compiler).
Some next steps this could enable:
Screen.Recording.2024-06-23.at.11.11.20.AM.mov
Next Steps
There are a few unanswered things here that we'll need to consider:
$schema
?///
comments very helpful and up to date.Acknowledgment
This PR aims to be a more maintainable and reliable alternative to #4569. Thanks for @noghartt for pushing the discussion of how we might fill this gap.
This approach was also previously explored in other PRs: