我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用graphene.Node()。
def setup_fixtures(): class ReporterType(PynamoObjectType): class Meta: model = Reporter interfaces = (Node,) class ArticleType(PynamoObjectType): class Meta: model = Article interfaces = (Node,) reporter1 = Reporter(1, first_name="John", last_name="Snow") article1 = Article(1, headline="Hi!", reporter=reporter1) article2 = Article(2, headline="Lame Article", reporter=reporter1) reporter1.articles = [article1, article2] return { 'ReporterType': ReporterType, 'ArticleType': ArticleType, 'reporter1': reporter1, 'article1': article1, 'article2': article2 }
def test_should_onetoone_convert_field(): class A(PynamoObjectType): class Meta: model = Article interfaces = (Node,) dynamic_field = convert_pynamo_attribute(Reporter.favorite_article, Reporter.favorite_article, A._meta.registry) assert isinstance(dynamic_field, Dynamic) graphene_type = dynamic_field.get_type() assert isinstance(graphene_type, graphene.Field) assert graphene_type.type == A
def test_should_onetomany_convert_field(): class A(PynamoObjectType): class Meta: model = Article interfaces = (Node,) dynamic_field = convert_pynamo_attribute(Reporter.articles, Reporter.articles, A._meta.registry) assert isinstance(dynamic_field, Dynamic) graphene_type = dynamic_field.get_type() assert isinstance(graphene_type, PynamoConnectionField)