-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closes #7598: Enable custom field filtering for GraphQL #18701
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
cca556c
Closes #7598: GraphQL Filter Redesign
jeremypng ddbda68
Update netbox/netbox/tests/test_graphql.py
jeremypng 2482c18
cleanup enums, enable strawberry-django optimizer, extra line
jeremypng 02942fa
removing commented enum
jeremypng f1d7ad8
moving filter_lookups.py to netbox/graphql
jeremypng 36dc8cd
Generate Strawberry filter enums from ChoiceSets (#18676)
jeremystretch 186be5f
Update GraphQL filter documentation
jeremystretch 5fcf32c
Apply tenant filters consistently
jeremystretch 380c9c1
Introduce ScopedFilterMixin
jeremystretch c369ac9
Misc cleanup
jeremystretch 8894c35
Add missing GraphQL filters
jeremystretch 3a7edf3
Clean up imports
jeremystretch 52b0555
Clean up typing for GraphQL types
jeremystretch 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
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,20 @@ | ||
| import strawberry | ||
|
|
||
| from circuits.choices import * | ||
|
|
||
| __all__ = ( | ||
| 'CircuitStatusEnum', | ||
| 'CircuitCommitRateEnum', | ||
| 'CircuitTerminationSideEnum', | ||
| 'CircuitTerminationPortSpeedEnum', | ||
| 'CircuitPriorityEnum', | ||
| 'VirtualCircuitTerminationRoleEnum', | ||
| ) | ||
|
|
||
|
|
||
| CircuitCommitRateEnum = strawberry.enum(CircuitCommitRateChoices.as_enum()) | ||
| CircuitPriorityEnum = strawberry.enum(CircuitPriorityChoices.as_enum()) | ||
| CircuitStatusEnum = strawberry.enum(CircuitStatusChoices.as_enum()) | ||
| CircuitTerminationSideEnum = strawberry.enum(CircuitTerminationSideChoices.as_enum()) | ||
| CircuitTerminationPortSpeedEnum = strawberry.enum(CircuitTerminationPortSpeedChoices.as_enum()) | ||
| VirtualCircuitTerminationRoleEnum = strawberry.enum(VirtualCircuitTerminationRoleChoices.as_enum()) |
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,19 @@ | ||
| from dataclasses import dataclass | ||
| from typing import Annotated, TYPE_CHECKING | ||
|
|
||
| import strawberry | ||
| import strawberry_django | ||
|
|
||
| from netbox.graphql.filter_mixins import OrganizationalModelFilterMixin | ||
|
|
||
| if TYPE_CHECKING: | ||
| from netbox.graphql.enums import ColorEnum | ||
|
|
||
| __all__ = ( | ||
| 'BaseCircuitTypeFilterMixin', | ||
| ) | ||
|
|
||
|
|
||
| @dataclass | ||
| class BaseCircuitTypeFilterMixin(OrganizationalModelFilterMixin): | ||
| color: Annotated['ColorEnum', strawberry.lazy('netbox.graphql.enums')] | None = strawberry_django.filter_field() |
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
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.
@jeremypng do you know whether it's necessary to define these filters explicitly? Setting them to
autoseems to yield the same schema, but I wanted to check if you had run into any problems with this approach.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.
If it can successfully infer the filter type from the field type it will work. From what I saw, this generally works for model fields that are physical database fields but not computed fields.
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.
That makes sense, thanks!