-
-
Notifications
You must be signed in to change notification settings - Fork 536
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
Refactor the backend typing system #906
Conversation
# Conflicts: # strawberry/field.py
Thanks for adding the Here's a preview of the changelog: Refactor of the library's typing internals. Previously, typing was handled Mainly replaces the attributes that were stored on StrawberryArgument and Introduces This is a breaking change if you were calling the constructor for
|
d70f3b5
to
825bc9b
Compare
# Conflicts: # strawberry/field.py
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'll test this on our work repo as soon as it is released. I tested it already, but I think we did some changes after that :)
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.
Nice work! Added some comments
strawberry/arguments.py
Outdated
raise MultipleStrawberryArgumentsError( | ||
field_name=origin.__name__, argument_name=python_name | ||
# TODO: This isn't the field name, it is the argument name | ||
field_name=self.python_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.
Do we no longer have access to the field at this point? It makes the error message nicer if we can say which field has the issue.
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.
Yeah, we no longer have access to the field name here. I would agree it makes the error better, but I don't have a good idea of how to do it.
I believe that @patrick91 and I agreed to just include this regression (I should open an issue for it, thanks for the reminder), but I'm open to suggestions.
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.
yes :) I think we can change a bit how we handle these errors, I'd love to have a better message and visualisation (for example pointing to the actual line), but that's something for the future :)
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.
Ok in that case can you update the exception message to not include the bit about the field name: https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/exceptions.py#L121-L128
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.
The test for it is now an xfail. I think we eventually want to go back to having the field name in the exception message. Should we still change it now?
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 think we should change it because otherwise we have a misleading error message.
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.
good point :D
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.
Ok changed the error message for now
…into feature/strawberry_type_system
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 PR is a refactor of the typing system within the library. Previously, typing was handled individually by fields, arguments, and types with a hodgepodge of functions to tie it together. This branch creates a unified typing system that the object, fields, and arguments each hook into.
This PR mainly replaces the attributes that were stored on
StrawberryArgument
andStrawberryField
with a hierarchy ofStrawberryType
s.There is more work to be done in the future, especially related to unifying the system by removing
.type_definition
and._enum_definition
monkeypatching.There is also some future discussion to be had on this PR's implementation of
StrawberryType.__eq__
, but current thoughts are to look back into it after this PR is merged.See #1063 for testing additions. This was done to prevent this PR from getting too long. It is also a good place to look to see how the changes here work.
To Do
- [ ] Tests involvingStrawberryType.__eq__
- [ ] Think longer about how to implementStrawberryType.__hash__
. Currently breaking the hash contract- [ ] New unit tests for theStrawberryType
types(@patrick91 and I decided this should be addressed in another discussion/PR after this one is merged)
Types of Changes
Issues Fixed or Closed by This PR
Checklist