-
Notifications
You must be signed in to change notification settings - Fork 58
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
Apply query_params to plural field. Fixes #219 #225
Open
flyte
wants to merge
3
commits into
torchbox:main
Choose a base branch
from
flyte:feature/plural_query_fields
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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,112 @@ | ||
from home.factories import PersonFactory | ||
|
||
from example.tests.test_grapple import BaseGrappleTest | ||
|
||
|
||
class PersonTest(BaseGrappleTest): | ||
def setUp(self): | ||
super().setUp() | ||
# Create person | ||
self.person1 = PersonFactory(name="Chuck Norris", job="Roundhouse Kicker") | ||
self.person2 = PersonFactory(name="Rory", job="Dog") | ||
|
||
def validate_person(self, person): | ||
# Check all the fields | ||
self.assertTrue(isinstance(person["id"], str)) | ||
self.assertTrue(isinstance(person["name"], str)) | ||
self.assertTrue(isinstance(person["job"], str)) | ||
|
||
def test_people_query(self): | ||
query = """ | ||
{ | ||
people { | ||
id | ||
name | ||
job | ||
} | ||
} | ||
""" | ||
executed = self.client.execute(query) | ||
person = executed["data"]["people"][0] | ||
|
||
# Check all the fields | ||
self.validate_person(person) | ||
|
||
def test_people_paginated_query(self): | ||
query = """ | ||
{ | ||
peoplePaginated { | ||
items { | ||
id | ||
name | ||
job | ||
} | ||
pagination { | ||
total | ||
count | ||
} | ||
} | ||
} | ||
""" | ||
executed = self.client.execute(query) | ||
person = executed["data"]["peoplePaginated"]["items"][0] | ||
|
||
# Check all the fields | ||
self.validate_person(person) | ||
|
||
def test_people_query_fields(self): | ||
query = """ | ||
query($job: String) { | ||
people(job: $job) { | ||
id | ||
name | ||
job | ||
} | ||
} | ||
""" | ||
executed = self.client.execute(query, variables={"job": self.person1.job}) | ||
person = executed["data"]["people"][0] | ||
|
||
# Check all the fields | ||
self.validate_person(person) | ||
self.assertEqual(person["name"], self.person1.name) | ||
|
||
def test_people_paginated_query_fields(self): | ||
query = """ | ||
query($job: String) { | ||
peoplePaginated(job: $job) { | ||
items { | ||
id | ||
name | ||
job | ||
} | ||
pagination { | ||
total | ||
count | ||
} | ||
} | ||
} | ||
""" | ||
executed = self.client.execute(query, variables={"job": self.person2.job}) | ||
person = executed["data"]["peoplePaginated"]["items"][0] | ||
|
||
# Check all the fields | ||
self.validate_person(person) | ||
self.assertEqual(person["name"], self.person2.name) | ||
|
||
def test_person_single_query(self): | ||
query = """ | ||
query($name: String) { | ||
person(name: $name) { | ||
id | ||
name | ||
job | ||
} | ||
} | ||
""" | ||
executed = self.client.execute(query, variables={"name": self.person1.name}) | ||
person = executed["data"]["person"] | ||
|
||
# Check all the fields | ||
self.validate_person(person) | ||
self.assertEqual(person["name"], self.person1.name) |
This file contains 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 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 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
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.
My main gripe with this approach is that it introduces yet another decorator, when it should not need to.
@register_query_field
supports plurality via theplural_field_name
kwarg, so we should make that work.register_singular_query_field
is a convenience decorator for very narrow uses cases, such as Wagtail Page models withmax_count = 1
Finally, #219 (comment) is an important use case, which this particular example covers, but as mentioned above it would be better to handle within the existing decorators, so
register_paginated_query_field
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.
@zerolab on the other hand it may be nice to separate @register_singular_query_field and @register_plural_query_field to make it simpler to document. Decorators in my experience tend to do discrete things. Having one decorator that sets up two different fields means we need to explain how both behave under one heading when each is going to have distinct arguments and return types.
Where as if we had both individual decorators, then the aggregate decorator can be explained by linking to both... just a thought... Maybe not something to include in this fix, but something to think about long term.
an example of our existing docs
all of those plural_* fields are only valuable if plural_field_name is set and have nothing to do with a singular fields
I almost feel like we should have
@register_model_query_singular
,@register_model_query_plural
,@register_model_query_paginated
. So users can choose to some something like...