mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
9856 Replace graphene with Strawberry (#15141)
* 9856 base strawberry integration * 9856 user and group * 9856 user and circuits base * 9856 extras and mixins * 9856 fk * 9856 update strawberry version * 9856 update imports * 9856 compatability fixes * 9856 compatability fixes * 9856 update strawberry types * 9856 update strawberry types * 9856 core schema * 9856 dcim schema * 9856 extras schema * 9856 ipam and tenant schema * 9856 virtualization, vpn, wireless schema * 9856 fix old decorator * 9856 cleanup * 9856 cleanup * 9856 fixes to circuits type specifiers * 9856 fixes to circuits type specifiers * 9856 update types * 9856 GFK working * 9856 GFK working * 9856 _name * 9856 misc fixes * 9856 type updates * 9856 _name to types * 9856 update types * 9856 update types * 9856 update types * 9856 update types * 9856 update types * 9856 update types * 9856 update types * 9856 update types * 9856 update types * 9856 GraphQLView * 9856 GraphQLView * 9856 fix OrganizationalObjectType * 9856 single item query for schema * 9856 circuits graphql tests working * 9856 test fixes * 9856 test fixes * 9856 test fixes * 9856 test fix vpn * 9856 test fixes * 9856 test fixes * 9856 test fixes * 9856 circuits test sans DjangoModelType * 9856 core test sans DjangoModelType * 9856 temp checkin * 9856 fix extas FK * 9856 fix tenancy FK * 9856 fix virtualization FK * 9856 fix vpn FK * 9856 fix wireless FK * 9856 fix ipam FK * 9856 fix partial dcim FK * 9856 fix dcim FK * 9856 fix virtualization FK * 9856 fix tests / remove debug code * 9856 fix test imagefield * 9856 cleanup graphene * 9856 fix plugin schema * 9856 fix requirements * 9856 fix requirements * 9856 fix docs * 9856 fix docs * 9856 temp fix tests * 9856 first filterset * 9856 first filterset * 9856 fix tests * 9856 fix tests * 9856 working auto filter generation * 9856 filter types * 9856 filter types * 9856 filter types * 9856 fix graphiql test * 9856 fix counter fields and merge feature * 9856 temp fix tests * 9856 fix tests * 9856 fix tenancy, ipam filter definitions * 9856 cleanup * 9856 cleanup * 9856 cleanup * 9856 review changes * 9856 review changes * 9856 review changes * 9856 fix base-requirements * 9856 add wrapper to graphiql * 9856 remove old graphiql debug toolbar * 9856 review changes * 9856 update strawberry * 9856 remove superfluous check --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
23
netbox/users/graphql/filters.py
Normal file
23
netbox/users/graphql/filters.py
Normal file
@ -0,0 +1,23 @@
|
||||
import strawberry
|
||||
import strawberry_django
|
||||
from django.contrib.auth import get_user_model
|
||||
from users import filtersets, models
|
||||
|
||||
from netbox.graphql.filter_mixins import autotype_decorator, BaseFilterMixin
|
||||
|
||||
__all__ = (
|
||||
'GroupFilter',
|
||||
'UserFilter',
|
||||
)
|
||||
|
||||
|
||||
@strawberry_django.filter(models.Group, lookups=True)
|
||||
@autotype_decorator(filtersets.GroupFilterSet)
|
||||
class GroupFilter(BaseFilterMixin):
|
||||
pass
|
||||
|
||||
|
||||
@strawberry_django.filter(get_user_model(), lookups=True)
|
||||
@autotype_decorator(filtersets.UserFilterSet)
|
||||
class UserFilter(BaseFilterMixin):
|
||||
pass
|
@ -1,21 +1,21 @@
|
||||
import graphene
|
||||
from django.contrib.auth import get_user_model
|
||||
from typing import List
|
||||
import strawberry
|
||||
import strawberry_django
|
||||
|
||||
from netbox.graphql.fields import ObjectField, ObjectListField
|
||||
from users.models import Group
|
||||
from utilities.graphql_optimizer import gql_query_optimizer
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group
|
||||
from users import models
|
||||
from .types import *
|
||||
|
||||
|
||||
class UsersQuery(graphene.ObjectType):
|
||||
group = ObjectField(GroupType)
|
||||
group_list = ObjectListField(GroupType)
|
||||
@strawberry.type
|
||||
class UsersQuery:
|
||||
@strawberry.field
|
||||
def group(self, id: int) -> GroupType:
|
||||
return models.Group.objects.get(pk=id)
|
||||
group_list: List[GroupType] = strawberry_django.field()
|
||||
|
||||
def resolve_group_list(root, info, **kwargs):
|
||||
return gql_query_optimizer(Group.objects.all(), info)
|
||||
|
||||
user = ObjectField(UserType)
|
||||
user_list = ObjectListField(UserType)
|
||||
|
||||
def resolve_user_list(root, info, **kwargs):
|
||||
return gql_query_optimizer(get_user_model().objects.all(), info)
|
||||
@strawberry.field
|
||||
def user(self, id: int) -> UserType:
|
||||
return models.User.objects.get(pk=id)
|
||||
user_list: List[UserType] = strawberry_django.field()
|
||||
|
@ -1,9 +1,14 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from graphene_django import DjangoObjectType
|
||||
from typing import List
|
||||
|
||||
import strawberry
|
||||
import strawberry_django
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group
|
||||
from strawberry import auto
|
||||
from users import filtersets
|
||||
from users.models import Group
|
||||
from utilities.querysets import RestrictedQuerySet
|
||||
from .filters import *
|
||||
|
||||
__all__ = (
|
||||
'GroupType',
|
||||
@ -11,28 +16,24 @@ __all__ = (
|
||||
)
|
||||
|
||||
|
||||
class GroupType(DjangoObjectType):
|
||||
|
||||
class Meta:
|
||||
model = Group
|
||||
fields = ('id', 'name')
|
||||
filterset_class = filtersets.GroupFilterSet
|
||||
|
||||
@classmethod
|
||||
def get_queryset(cls, queryset, info):
|
||||
return RestrictedQuerySet(model=Group).restrict(info.context.user, 'view')
|
||||
@strawberry_django.type(
|
||||
Group,
|
||||
fields=['id', 'name'],
|
||||
filters=GroupFilter
|
||||
)
|
||||
class GroupType:
|
||||
pass
|
||||
|
||||
|
||||
class UserType(DjangoObjectType):
|
||||
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = (
|
||||
'id', 'username', 'password', 'first_name', 'last_name', 'email', 'is_staff', 'is_active', 'date_joined',
|
||||
'groups',
|
||||
)
|
||||
filterset_class = filtersets.UserFilterSet
|
||||
|
||||
@classmethod
|
||||
def get_queryset(cls, queryset, info):
|
||||
return RestrictedQuerySet(model=get_user_model()).restrict(info.context.user, 'view')
|
||||
@strawberry_django.type(
|
||||
get_user_model(),
|
||||
fields=[
|
||||
'id', 'username', 'password', 'first_name', 'last_name', 'email', 'is_staff',
|
||||
'is_active', 'date_joined', 'groups',
|
||||
],
|
||||
filters=UserFilter
|
||||
)
|
||||
class UserType:
|
||||
@strawberry_django.field
|
||||
def groups(self) -> List[GroupType]:
|
||||
return self.groups.all()
|
||||
|
Reference in New Issue
Block a user