그래서 내 모델은
class Abcd(models.Model):
name = models.CharField(max_length=30, default=False)
data = models.CharField(max_length=500, blank=True, default=False)
모델의 일부가 아닌 쿼리 시간에 사전을 전달해야합니다. 쿼리는
query {
allAbcd(Name: "XYZ") {
edges {
node {
Data
}
}
}
}
쿼리와 함께 이러한 사용자 정의 필드를 어떻게 전달합니까?
이 사용자 정의 필드는 다른 프로세스 목적에 필요합니다.
Graphene은 유형을 사용하여 모델에 전혀 연결되어 있지 않은 노드를 확인하고 어떤 모델과도 연결되지 않은 Graphene 유형을 정의 할 수도 있습니다. 어쨌든 당신이 찾고있는 사용 사례는 매우 간단합니다. 예를 들어 모델 이름 User
이 있다고 가정 해 봅시다 Data
. 모델의 리졸버 가이 문제를 해결해야 한다고 가정합니다 .
from graphene.relay import Node
from graphene import ObjectType, JSONField, String
from graphene_django import DjangoObjectType
from app.models import User
class UserType(DjangoObjectType):
class Meta:
filter_fields = {'id': ['exact']}
model = User
custom_field = JSONField()
hello_world = String()
@staticmethod
def resolve_custom_field(root, info, **kwargs):
return {'msg': 'That was easy!'} # or json.dumps perhaps? you get the idea
@staticmethod
def resolve_hello_world(root, info, **kwargs):
return 'Hello, World!'
class Query(ObjectType):
user = Node.Field(UserType)
all_users = DjangoFilterConnectionField(ProjectType)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다