Initial commit: React + Django 城市手册项目
- Django 4.2 + DRF + JWT + GraphQL - React 18 + MobX + styled-components - PostgreSQL 数据库 - Docker + Docker Compose + Nginx - 完整的功能模块(用户、版块、文章、服务、交互、版主管理) - 完整的文档(需求、部署、测试)
This commit is contained in:
31
backend/apps/api/schema.py
Normal file
31
backend/apps/api/schema.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import graphene
|
||||
from graphene_django import DjangoObjectType
|
||||
from apps.users.models import User
|
||||
|
||||
|
||||
class UserType(DjangoObjectType):
|
||||
"""GraphQL type for User."""
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
"""Root GraphQL Query."""
|
||||
|
||||
all_users = graphene.List(UserType)
|
||||
me = graphene.Field(UserType)
|
||||
|
||||
def resolve_all_users(root, info):
|
||||
"""Resolve all users query."""
|
||||
return User.objects.all()
|
||||
|
||||
def resolve_me(root, info):
|
||||
"""Resolve current user query."""
|
||||
if info.context.user.is_authenticated:
|
||||
return info.context.user
|
||||
return None
|
||||
|
||||
|
||||
schema = graphene.Schema(query=Query)
|
||||
Reference in New Issue
Block a user