- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
说我有,
class PersonNode(DjangoObjectType):
class Meta:
model = Person
fields = ('first_name', 'last_name', 'age',
'sex', 'alive', 'unique_identifier',)
filter_fields = ('first_name', 'last_name', 'age',
'sex', 'alive', 'unique_identifier',)
interfaces = (graphene.relay.Node,)
class PersonNodeInput(graphene.InputObjectType):
first_name = graphene.String()
last_name = graphene.String()
# rest of person model fields
class Valid(graphene.ObjectType):
ok = graphene.Boolean()
class Query(graphene.ObjectType):
validate_person = graphene.Field(Valid, args={
"data": PersonNodeInput()})
person = graphene.relay.Node.Field(PersonNode)
all_people = DjangoFilterConnectionField(PersonNode)
def resolve_validate_person(root, info, data):
print("resolve validate person")
return Valid(ok=True)
是否可以避免写出 PersonNodeInput?如果您可以将“DjangoInputObjectType”之类的子类化并在 Meta 属性中指定您想要的模型和字段,那就太好了。
最佳答案
我们一直在使用这个 Graphene Django CUD试图删除一些涉及定义突变的样板的库。
根据他们的示例调整您的案例看起来像
from graphene_django_cud.mutations import DjangoCreateMutation
class CreatePersonMutation(DjangoCreateMutation):
class Meta:
model = Person
class PersonMutations(graphene.ObjectType):
create_person = CreateUserMutation.Field()
schema = Schema(mutation=PersonMutations)
我不知道它与 Relay 节点的配合情况如何,因为我们没有使用 Relay。
关于graphene-django - 有没有办法优雅地使用 django 模型作为输入对象类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66286436/
我尝试了解 Django 中的 Graphql 并使用 graphene和 graphene_django . 我的前端可能会使用 Vuejs 和 Apollo 客户端构建。 互联网上的所有教程都是关
我已经实现了 graphql 并且我正在迁移到中继。我已经为每个表创建了一个 uuid,名为“id”。我找到了我的应用程序 this github thread谈到可能会改变规范,但感觉就像一个兔子洞
不确定我设置错了什么,但是当我使用 uvicorn mysite.asgi:application 在 uvicorn 中运行时,我没有得到 graphiql 界面: [32mINFO[0m:
我想将状态字段添加到错误响应中,而不是这样: { "errors": [ { "message": "Authentication credentials were not p
我的 Django 模型中有一个图像字段,我正在尝试从 Graphene 获取图像字段输出的绝对路径。我记得使用 HttpRequest.build_absolute_uri 获取文件/图像字段的绝对
如果这个问题在其他地方得到回答,那么我很抱歉,但是下类后两天,仍然没有雪茄...... 我有一个播放器模型: class Player(models.Model): name = models
我的 Django 模型中有一个图像字段,我正在尝试从 Graphene 获取图像字段输出的绝对路径。我记得使用 HttpRequest.build_absolute_uri 获取文件/图像字段的绝对
我使用 Django 作为后端,使用 graphene-django 作为前端。我是 django 和 graphene 的新手,所以我不确定在这个设置中没有代码重复的情况下实现字段级权限的最佳方法是
我的应用程序有几个多对多关系 带直通型 像这样: class Person(models.Model): name = models.CharField() class Group(model
我想知道如何正确创建用于创建此 Django 模型的突变: class Company(models.Model): class Meta: db_table = 'compa
我使用 django 和 django graphene 来制作 graphql API。 在我的应用程序中,我使用reactJS和react-bootstrap-table 。 React-boot
我目前正在使用 Python-Graphene 为我的 Django 应用程序创建一个 GraphQL 接口(interface)。虽然查询效果很好,但突变 - 不完全是。 成分的模型: class
假设一个类似于此的 Django 模型: class Profile(models.Model): user = models.OneToOneField(User, on_delete=
我使用 graphen-django 构建 GraphQL API。我已成功创建此 API,但无法传递参数来过滤我的响应。 这是我的 models.py: from django.db import
我在 Django 对象类型定义中遇到 get_node 方法的问题。在我的案例中似乎没有调用该方法。 我什至尝试通过在 get_node 方法中暂停执行来使用 pdb 进行调试,但也没有用。 这是我
到目前为止,我可以在不需要 DjangoObjectType 的情况下使用 Graphene。我尽量避免它,因为我不打算离我的 Django 模型类太近。但是我在使用 Graphene 实现 Rela
说我有, class PersonNode(DjangoObjectType): class Meta: model = Person fields = ('f
所以我的模型看起来像 class Abcd(models.Model): name = models.CharField(max_length=30, default=False) d
目前使用graphene-python 和graphene-django(和graphene-django-optimizer)。 收到GraphQL查询后,数据库查询在几分之一秒内成功完成;然而,
每当引发异常时,它们都会记录在控制台中(如果使用了 Sentry,则记录在 Sentry 中)。 许多这些异常(exception)仅旨在向用户显示。例如, django-graphql-jwt ra
我是一名优秀的程序员,十分优秀!