我使用石墨烯和石墨烯-mongo。我的graphql模式有一个类似如下的类型: type Report {
id:ID!
name:String!
} 我针对这种类型的石墨烯类是 class Product(MongoengineObjectType):
class Meta:
model = MongoProduct 而mongoengine类是 class MongoProduct(mng.DynamicDocument):
name = mng.fields.StringField(required=True) 如何将该字段
我在用石墨烯做实验
1.)字段的默认值(就像python中的defaultdict一样)
例:-
Class something(graphene.ObjectType):
FieldA = graphene.Float() or return a defaultValue
2.)设置多类型字段
例:-
Class something(graphene.ObjectType):
FieldA = graphene.Float() or graphene.String() or None
我对石墨烯还不熟悉&我正在查阅文档。
在完成上述2项工作时,任何帮助/指针都将受到赞
我正在使用石墨烯构建graphQL模式,并使用mypy进行静态类型检查。schema的代码开始如下:
from typing import Dict, List, NamedTuple, Union
import graphene
class PossibleAnswer(graphene.ObjectType):
"""Object representing single possible answer, a pair of key and text."""
paId = graphene.String(
我使用django和django石墨烯来生成graphql。
在我的应用程序中,我使用reactJS和。React引导表期望我为它传递一个对象数组,但不支持。
我在schema.py中创建了查询
class ApplicationNode(DjangoObjectType):
class Meta:
model = Application
filter_fields = ['name', 'sonarQube_URL']
interfaces = (relay.Node,)
class Query(Obj
如何为石墨烯-django中的react-relay创建一个查看器字段?这并不像预期的那样工作。我使用的是石墨烯-django v.2.2。Django 2.1。React-relay v1.7.0-rc.1。
// landingpage.schema.py
class CollectionNode(DjangoObjectType):
class Meta:
model = Collection
interfaces = (relay.Node, )
class Viewer(graphene.ObjectType):
class Meta:
inter
我的石墨烯模式上有客户、用户、项目和Trips:
class Clients(SQLAlchemyObjectType):
class Meta:
model = ClientModel
interfaces = (relay.Node, )
class Users(SQLAlchemyObjectType):
class Meta:
model = UserModel
interfaces = (relay.Node, )
class Projects(SQLAlchemyObjectType):
c
我阅读了关于如何在解析器中使用和其他装饰器的说明。但是,如果不使用显式解析器(而是使用默认解析器),如何实施类似的访问控制?
在我的例子中,我将石墨烯与Django用户模型一起使用。我有以下几点:
class UserNode(DjangoObjectType):
class Meta:
model = User
filter_fields = ['first_name', 'last_name', 'id', 'email']
interfaces = (Node, )
Aiohttp提供一个上下文管理器来创建客户端会话。建议每多个http查询使用一个会话(在大多数情况下,每个应用程序)
但是,石墨烯使用的解析器需要声明为类方法:
石墨烯的也存在异步执行器,有任何方法在异步环境下执行所有解析器吗?
示例:
async def get_task(session, api_url, id):
""" Function to resolve task from rest API"""
async with session.get(api_url+id) as response:
ret
我有一个Django Log模型,它具有多对一的User。
from django.db import models
class Log(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
...
我有一个Log的Django表单
from django.forms import ModelForm
class LogForm(ModelForm):
class Meta:
model = Log
exclude = ("user
我想测试我的graphql突变,它应该只设置一个HTTP cookie。
我使用石墨烯-django
class CookieTest(GraphQLTestCase):
def test_set_cookie(self):
response = self.query(...) # This should return WSGIRequest
cookie = response.COOKIES.get('myCookie') # This line throws an attrib error
self.assertIsNotNone(cookie)