-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Closes #7598: GraphQL Filter Redesign #18618
Open
jeremypng
wants to merge
5
commits into
netbox-community:feature
Choose a base branch
from
jeremypng:graphql-filter-redesign
base: feature
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.
+4,465
−633
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
999cae9
Closes #7598: GraphQL Filter Redesign
jeremypng 03be7d2
Update netbox/netbox/tests/test_graphql.py
jeremypng 489b084
cleanup enums, enable strawberry-django optimizer, extra line
jeremypng e3e2e5d
removing commented enum
jeremypng cfa8291
moving filter_lookups.py to netbox/graphql
jeremypng 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from enum import Enum | ||
import strawberry | ||
|
||
__all__ = [ | ||
'CircuitStatusEnum', | ||
'CircuitCommitRateEnum', | ||
'CircuitTerminationSideEnum', | ||
'CircuitTerminationPortSpeedEnum', | ||
'CircuitPriorityEnum', | ||
'VirtualCircuitTerminationRoleEnum', | ||
] | ||
|
||
# | ||
# Circuits | ||
# | ||
|
||
|
||
@strawberry.enum | ||
class CircuitStatusEnum(Enum): | ||
STATUS_DEPROVISIONING = 'deprovisioning' | ||
STATUS_ACTIVE = 'active' | ||
STATUS_PLANNED = 'planned' | ||
STATUS_PROVISIONING = 'provisioning' | ||
STATUS_OFFLINE = 'offline' | ||
STATUS_DECOMMISSIONED = 'decommissioned' | ||
|
||
|
||
@strawberry.enum | ||
class CircuitCommitRateEnum(Enum): | ||
TEN_MBPS = 10000 | ||
HUNDRED_MBPS = 100000 | ||
ONE_GBPS = 1000000 | ||
TEN_GBPS = 10000000 | ||
TWENTY_FIVE_GBPS = 25000000 | ||
FORTY_GBPS = 40000000 | ||
HUNDRED_GBPS = 100000000 | ||
TWO_HUNDRED_GBPS = 200000000 | ||
FOUR_HUNDRED_GBPS = 400000000 | ||
T1 = 1544 | ||
E1 = 2048 | ||
|
||
|
||
# | ||
# CircuitTerminations | ||
# | ||
|
||
|
||
@strawberry.enum | ||
class CircuitTerminationSideEnum(Enum): | ||
SIDE_A = 'A' | ||
SIDE_Z = 'Z' | ||
|
||
|
||
@strawberry.enum | ||
class CircuitTerminationPortSpeedEnum(Enum): | ||
TEN_MBPS = 10000 | ||
HUNDRED_MBPS = 100000 | ||
ONE_GBPS = 1000000 | ||
TEN_GBPS = 10000000 | ||
TWENTY_FIVE_GBPS = 25000000 | ||
FORTY_GBPS = 40000000 | ||
HUNDRED_GBPS = 100000000 | ||
TWO_HUNDRED_GBPS = 200000000 | ||
FOUR_HUNDRED_GBPS = 400000000 | ||
T1 = 1544 | ||
E1 = 2048 | ||
|
||
|
||
@strawberry.enum | ||
class CircuitPriorityEnum(Enum): | ||
PRIORITY_PRIMARY = 'primary' | ||
PRIORITY_SECONDARY = 'secondary' | ||
PRIORITY_TERTIARY = 'tertiary' | ||
PRIORITY_INACTIVE = 'inactive' | ||
|
||
|
||
# | ||
# Virtual circuits | ||
# | ||
|
||
|
||
@strawberry.enum | ||
class VirtualCircuitTerminationRoleEnum(Enum): | ||
ROLE_PEER = 'peer' | ||
ROLE_HUB = 'hub' | ||
ROLE_SPOKE = 'spoke' |
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,17 @@ | ||
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 .filters import * | ||
from core.graphql.filter_lookups import * | ||
from netbox.graphql.enums import * | ||
|
||
__all__ = ['BaseCircuitTypeFilterMixin'] | ||
|
||
|
||
@dataclass | ||
class BaseCircuitTypeFilterMixin(OrganizationalModelFilterMixin): | ||
color: Annotated['ColorEnum', strawberry.lazy('netbox.graphql.enums')] | None = strawberry_django.filter_field() |
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
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.
We should be able to generate these enums programmatically from the ChoiceSet subclasses NetBox already defines. That would save us quite a bit of duplication. I'm happy to tackle this work if you're in agreement with the 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.
I second the vote for auto-generating the enums, much easier to maintain.
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’m good with either one of us tackling it. It will make the code harder to validate in your IDE because the type checking won’t have anything to match against. But that shouldn’t affect the GraphQL schema generation which is the most important part.
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.
What do you think about a Django command to generate the enum files from the choice modules? That keeps the type checking in place for development, but would allow them to be easily updated with each release.