-
-
Notifications
You must be signed in to change notification settings - Fork 799
Use correct type name when referencing type with ID<Type> #8504
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a0a2e3a
Honor GraphQLName`s and fluent definition type names for ID<T>
N-Olbert b6f3795
Reworked tests
N-Olbert 2976ce4
Merge branch 'main' into 6256
michaelstaib 6c755c8
Apply suggestions from code review
N-Olbert 09b2c83
Adjustments from review
N-Olbert 977e23d
Merge branch 'main' into 6256
N-Olbert e61fdd5
Reformat multiline string in `IdDescriptorTests` for consistent inden…
N-Olbert 1561970
Second attempt on indentation
N-Olbert 2307571
Merge branch 'main' into 6256
glen-84 cc0f9d9
Fixed CS8618 error
glen-84 eae3519
Merge branch 'main' into 6256
michaelstaib 8cb39fd
Merge branch 'main' into 6256
michaelstaib 0d109b8
Merge branch 'main' into 6256
michaelstaib File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/HotChocolate/Core/src/Types/Types/Relay/NodeIdNameDefinitionUnion.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| namespace HotChocolate.Types.Relay; | ||
|
|
||
| /// <summary> | ||
| /// A discriminated union, containing either a literal or a type that defines | ||
| /// the name of the node identifier. | ||
| /// </summary> | ||
| internal record NodeIdNameDefinitionUnion(string? Literal, Type? Type) | ||
| { | ||
| public static NodeIdNameDefinitionUnion? Create(string? literal) => | ||
| literal == null ? null : new NodeIdNameDefinitionUnion(literal, null); | ||
|
|
||
| public static NodeIdNameDefinitionUnion Create<T>() => | ||
| new NodeIdNameDefinitionUnion(null, typeof(T)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why not for the interface?
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.
@michaelstaib Two reasons:
type Cat implements Node & IPet, theIDwill be something likebase64(concat("Cat", Id))- and notbase64(concat("IPet", Id)). Therefore, having something likepublic bool? IsHungry([ID<IPet>] int petId)is almost guaranteed to fail, as theIDwill never start with"IPet".With the current implementation
public bool? IsHungry([ID<IPet>] int petId)should work fine as it is converted implicitly topublic bool? IsHungry([ID] int petId). Note that I haven't tested this, but this is my current understanding of how it is supposed to work (will verify it during the weekend).However... the implicit conversion from ID to ID may or may not be what the user expects, at least it is not obvious. Since HC has analyzers now: Wouldn’t it be better to simply throw a schema exception for interfaces here and instead have an analyzer that flags such cases and offers a code fix from ID to ID?
Your thoughts on this? Am I missing a case where this would/should work?
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.
You are correct ... was just skimming through the code. In this case we only need the GraphQL type information but not the runtime type.
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.
👍 Do you also agree on throwing an exception and / or adding an analyzer instead? The implicit rewrite seems problematic as the field now accepts any ID which is clearly not what the developer intended.
I can add this if we decide that it's desired (not as part of this PR, but as a follow-up).