-
Notifications
You must be signed in to change notification settings - Fork 318
refactor(composition): Allow different source and dest types in mismatch reports #8307
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
Conversation
…nodes in mismatch messages
… other than for missing descriptions
@tninesling, please consider creating a changeset entry in |
✅ Docs preview has no changesThe preview was not built because there were no changes. Build ID: 0e3ae2d0f5dc84897a9aa7de |
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.
Had two questions, but overall I appreciate the description. It helped with understanding what was refactored and how we can make mismatch reports more permissive using these new different source and destination types.
}, | ||
&directive, | ||
&definition_sources, | ||
|def| Some(format!("\"@{}\"", def.name)), |
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.
nit: maybe we can make this into a function to remove redundancy between two lines?
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.
I get the idea, but I think it's largely up to stylistic preference. Personally, I'd rather save the couple lines and keep these inlined since they're relatively short.
// determine which one we selected when it's looking through the sources. | ||
pos.insert_directive(&mut self.merged, most_used_directive.clone())?; | ||
self.error_reporter.report_mismatch_hint::<Directive, ()>( | ||
fn print_arguments(elt: &Directive) -> Option<String> { |
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.
Is this a function that we might be able to expose for additional usages?
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.
As far as I can tell, this formatting is fairly specific to this error message. Most other places would use the coordinate format, so I don't think this generalizes
Making mismatch reports more permissive
The TS implementation of
reportMismatch
and its related variants assumed that we were always working on AST nodes. So, it used the same generic typeT
for both sources and the destination. In Rust, we often work with position representations which are used to get the AST nodes later on. This means we may have a destination position paired with a list of AST node sources, or we may have an in-memory destination AST node and a set of source positions. This change aims to make it easier to generate mismatch reports from those situations where the types don't exactly match.Splitting source and destination types
The main change here is the update to the
report_mismatch
type signature, which now has separate type parameters for source types and destination types.Instead of the
T
for type andU
for node location, the signature now usesD
for destination,S
for source, andL
for location. This necessitates different functions for themismatch_accessor
, which was previously defined asmismatch_accessor: impl Fn(&T, bool) -> Option<String>
where the boolean parameter indicated whether this instance ofT
was the supergraph element or not. Now, we have two different accessor functions to account for the type difference:Supplying subgraph index to source accessor
The
subgraph_mismatch_accessor
now receives the subgraph index corresponding to the instance ofS
you're operating on. This is important when yourSources<&S>
contains positions, and you want to access the actual AST nodes from the schema when generating your message.Removal of ignore predicate
The
ignore_predicate
for mismatch accessors was almost never used. In the TS source, it was alwaysundefined
, except for when our mismatch accessor returned undefined descriptions. This meant we were almost always passingNone
for this value when using the mismatch reporter, but Rust made us define ugly types for the function we weren't passing (likeNone::<fn(Option<&DirectiveDefinitionPosition>) -> bool>
).Instead, we skip
None
outputs from the accessor, since they were being coalesced to empty strings in the messages anyway. This means we avoid the possibility of getting messages likeA mismatch was found in , , and
while removing the need to write these annoying signatures for theNone
case.Checklist
Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.
Exceptions
Note any exceptions here
Notes
Footnotes
It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this. ↩
Configuration is an important part of many changes. Where applicable please try to document configuration examples. ↩
A lot of (if not most) features benefit from built-in observability and
debug
-level logs. Please read this guidance on metrics best-practices. ↩Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions. ↩