9856 base strawberry integration

This commit is contained in:
Arthur 2023-08-22 16:39:04 -07:00
parent 5709bc3b2b
commit 3f2c21f005
5 changed files with 24 additions and 32 deletions

View File

@ -132,8 +132,12 @@ social-auth-core
# https://github.com/python-social-auth/social-app-django/blob/master/CHANGELOG.md
social-auth-app-django
# Enhanced Strawberry GraphQL integration with Django
# https://github.com/blb-ventures/strawberry-django-plus/blob/main/CHANGELOG.md
strawberry-graphql-django
# SVG image rendering (used for rack elevations)
# hhttps://github.com/mozman/svgwrite/blob/master/NEWS.rst
# https://github.com/mozman/svgwrite/blob/master/NEWS.rst
svgwrite
# Tabular dataset library (for table-based exports)

View File

@ -1,31 +1,18 @@
import graphene
from circuits.graphql.schema import CircuitsQuery
from core.graphql.schema import CoreQuery
from dcim.graphql.schema import DCIMQuery
from extras.graphql.schema import ExtrasQuery
from ipam.graphql.schema import IPAMQuery
from netbox.registry import registry
from tenancy.graphql.schema import TenancyQuery
from users.graphql.schema import UsersQuery
from virtualization.graphql.schema import VirtualizationQuery
from wireless.graphql.schema import WirelessQuery
import strawberry
from strawberry_django.optimizer import DjangoOptimizerExtension
class Query(
UsersQuery,
CircuitsQuery,
CoreQuery,
DCIMQuery,
ExtrasQuery,
IPAMQuery,
TenancyQuery,
VirtualizationQuery,
WirelessQuery,
*registry['plugins']['graphql_schemas'], # Append plugin schemas
graphene.ObjectType
):
pass
@strawberry.type
class User:
name: str
age: int
schema = graphene.Schema(query=Query, auto_camelcase=False)
@strawberry.type
class Query:
@strawberry.field
def user(self) -> User:
return User(name="Patrick", age=100)
schema = strawberry.Schema(query=Query)

View File

@ -361,7 +361,7 @@ INSTALLED_APPS = [
'django_filters',
'django_tables2',
'django_prometheus',
'graphene_django',
'strawberry_django',
'mptt',
'rest_framework',
'social_django',
@ -385,7 +385,7 @@ INSTALLED_APPS = [
# Middleware
MIDDLEWARE = [
'graphiql_debug_toolbar.middleware.DebugToolbarMiddleware',
"strawberry_django.middlewares.debug_toolbar.DebugToolbarMiddleware",
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',

View File

@ -9,8 +9,8 @@ from account.views import LoginView, LogoutView
from extras.plugins.urls import plugin_admin_patterns, plugin_patterns, plugin_api_patterns
from netbox.api.views import APIRootView, StatusView
from netbox.graphql.schema import schema
from netbox.graphql.views import GraphQLView
from netbox.views import HomeView, StaticMediaFailureView, SearchView, htmx
from strawberry.django.views import GraphQLView
from .admin import admin_site
_patterns = [
@ -59,7 +59,7 @@ _patterns = [
path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='api_redocs'),
# GraphQL
path('graphql/', csrf_exempt(GraphQLView.as_view(graphiql=True, schema=schema)), name='graphql'),
path('graphql/', GraphQLView.as_view(schema=schema), name='graphql'),
# Serving static media in Django to pipe it through LoginRequiredMiddleware
path('media/<path:path>', serve, {'document_root': settings.MEDIA_ROOT}),

View File

@ -30,6 +30,7 @@ PyYAML==6.0.1
sentry-sdk==1.29.2
social-auth-app-django==5.2.0
social-auth-core[openidconnect]==4.4.2
strawberry-graphql-django==0.16.0
svgwrite==1.4.3
tablib==3.5.0
tzdata==2023.3