Skip to content

Commit

Permalink
feat: Enable RecordType GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
fan9704 committed Aug 28, 2023
1 parent 4c3b6df commit ee7ba29
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
14 changes: 14 additions & 0 deletions PetMonitoringSystemBackend/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import graphene

from api import schema


class Query(schema.Query, graphene.ObjectType):
pass


class Mutation(schema.Mutation, graphene.ObjectType):
pass


schema = graphene.Schema(query=Query, mutation=Mutation)
29 changes: 29 additions & 0 deletions api/schema/RecordType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import graphene
from graphene_django.types import DjangoObjectType
from api.models import RecordType


class RecordTypeQL(DjangoObjectType):
class Meta:
model = RecordType


class RecordTypeDTO(graphene.InputObjectType):
type = graphene.String()


class CreateRecordType(graphene.Mutation):
class Arguments:
record_type_data = RecordTypeDTO()

success = graphene.Boolean()
record_type = graphene.Field(RecordTypeQL)

def mutate(self, info, record_type_data):
record_type = RecordType(
type=record_type_data.type
)
record_type.save()
return CreateRecordType(record_type=record_type, success=True)


0 comments on commit ee7ba29

Please sign in to comment.