Python graphene.relay.Node() Examples
The following are 28
code examples of graphene.relay.Node().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
graphene.relay
, or try the search function
.
Example #1
Source File: test_fields.py From graphene-django with MIT License | 6 votes |
def test_recursive_filter_connection(): class ReporterFilterNode(DjangoObjectType): child_reporters = DjangoFilterConnectionField(lambda: ReporterFilterNode) def resolve_child_reporters(self, **args): return [] class Meta: model = Reporter interfaces = (Node,) class Query(ObjectType): all_reporters = DjangoFilterConnectionField(ReporterFilterNode) assert ( ReporterFilterNode._meta.fields["child_reporters"].node_type == ReporterFilterNode )
Example #2
Source File: test_fields.py From graphene-django with MIT License | 6 votes |
def test_filter_filterset_information_on_meta_related(): class ReporterFilterNode(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) filter_fields = ["first_name", "articles"] class ArticleFilterNode(DjangoObjectType): class Meta: model = Article interfaces = (Node,) filter_fields = ["headline", "reporter"] class Query(ObjectType): all_reporters = DjangoFilterConnectionField(ReporterFilterNode) all_articles = DjangoFilterConnectionField(ArticleFilterNode) reporter = Field(ReporterFilterNode) article = Field(ArticleFilterNode) schema = Schema(query=Query) articles_field = ReporterFilterNode._meta.fields["articles"].get_type() assert_arguments(articles_field, "headline", "reporter") assert_not_orderable(articles_field)
Example #3
Source File: test_types.py From graphql-pynamodb with MIT License | 5 votes |
def test_pynamo_interface(): assert issubclass(Node, Interface) assert issubclass(Node, Node)
Example #4
Source File: test_fields.py From graphene-django with MIT License | 5 votes |
def test_filter_filterset_related_results_with_filter(): class ReporterFilterNode(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) filter_fields = {"first_name": ["icontains"]} class Query(ObjectType): all_reporters = DjangoFilterConnectionField(ReporterFilterNode) Reporter.objects.create( first_name="A test user", last_name="Last Name", email="test1@test.com" ) Reporter.objects.create( first_name="Other test user", last_name="Other Last Name", email="test2@test.com", ) Reporter.objects.create( first_name="Random", last_name="RandomLast", email="random@test.com" ) query = """ query { allReporters(firstName_Icontains: "test") { edges { node { id } } } } """ schema = Schema(query=Query) result = schema.execute(query) assert not result.errors # We should only get two reporters assert len(result.data["allReporters"]["edges"]) == 2
Example #5
Source File: test_fields.py From graphene-django with MIT License | 5 votes |
def test_filter_filterset_class_information_on_meta_related(): class ReporterFilter(FilterSet): class Meta: model = Reporter fields = ["first_name", "articles"] class ArticleFilter(FilterSet): class Meta: model = Article fields = ["headline", "reporter"] class ReporterFilterNode(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) filterset_class = ReporterFilter class ArticleFilterNode(DjangoObjectType): class Meta: model = Article interfaces = (Node,) filterset_class = ArticleFilter class Query(ObjectType): all_reporters = DjangoFilterConnectionField(ReporterFilterNode) all_articles = DjangoFilterConnectionField(ArticleFilterNode) reporter = Field(ReporterFilterNode) article = Field(ArticleFilterNode) schema = Schema(query=Query) articles_field = ReporterFilterNode._meta.fields["articles"].get_type() assert_arguments(articles_field, "headline", "reporter") assert_not_orderable(articles_field)
Example #6
Source File: test_fields.py From graphene-django with MIT License | 5 votes |
def test_filter_filterset_class_information_on_meta(): class ReporterFilter(FilterSet): class Meta: model = Reporter fields = ["first_name", "articles"] class ReporterFilterNode(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) filterset_class = ReporterFilter field = DjangoFilterConnectionField(ReporterFilterNode) assert_arguments(field, "first_name", "articles") assert_not_orderable(field)
Example #7
Source File: test_fields.py From graphene-django with MIT License | 5 votes |
def test_filter_filterset_class_filter_fields_exception(): with pytest.raises(Exception): class ReporterFilter(FilterSet): class Meta: model = Reporter fields = ["first_name", "articles"] class ReporterFilterNode(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) filterset_class = ReporterFilter filter_fields = ["first_name", "articles"]
Example #8
Source File: test_converter.py From graphene-django with MIT License | 5 votes |
def test_should_manytomany_convert_connectionorlist_connection(): class A(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) graphene_field = convert_django_field( Reporter._meta.local_many_to_many[0], A._meta.registry ) assert isinstance(graphene_field, graphene.Dynamic) dynamic_field = graphene_field.get_type() assert isinstance(dynamic_field, ConnectionField) assert dynamic_field.type.of_type == A._meta.connection
Example #9
Source File: test_fields.py From graphene-django with MIT License | 5 votes |
def test_annotation_with_only(): class ReporterType(DjangoObjectType): full_name = String() class Meta: model = Reporter interfaces = (Node,) filter_fields = () class Query(ObjectType): all_reporters = DjangoFilterConnectionField(ReporterType) def resolve_all_reporters(self, info, **args): return Reporter.objects.only("first_name", "last_name").annotate( full_name=Concat( "first_name", Value(" "), "last_name", output_field=TextField() ) ) Reporter.objects.create(first_name="John", last_name="Doe") schema = Schema(query=Query) query = """ query NodeFilteringQuery { allReporters(first: 1) { edges { node { fullName } } } } """ expected = {"allReporters": {"edges": [{"node": {"fullName": "John Doe"}}]}} result = schema.execute(query) assert not result.errors assert result.data == expected
Example #10
Source File: test_query.py From graphene-django with MIT License | 5 votes |
def test_should_query_list(): r1 = Reporter(last_name="ABA") r1.save() r2 = Reporter(last_name="Griffin") r2.save() class ReporterType(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) class Query(graphene.ObjectType): all_reporters = graphene.List(ReporterType) debug = graphene.Field(DjangoDebug, name="__debug") def resolve_all_reporters(self, info, **args): return Reporter.objects.all() query = """ query ReporterQuery { allReporters { lastName } __debug { sql { rawSql } } } """ expected = { "allReporters": [{"lastName": "ABA"}, {"lastName": "Griffin"}], "__debug": {"sql": [{"rawSql": str(Reporter.objects.all().query)}]}, } schema = graphene.Schema(query=Query) result = schema.execute( query, context_value=context(), middleware=[DjangoDebugMiddleware()] ) assert not result.errors assert result.data == expected
Example #11
Source File: test_types.py From graphene-mongo with MIT License | 5 votes |
def test_mongoengine_interface(): assert issubclass(Node, Interface) assert issubclass(Node, Node)
Example #12
Source File: test_batching.py From graphene-sqlalchemy with MIT License | 5 votes |
def get_schema(): class ReporterType(SQLAlchemyObjectType): class Meta: model = Reporter interfaces = (relay.Node,) batching = True class ArticleType(SQLAlchemyObjectType): class Meta: model = Article interfaces = (relay.Node,) batching = True class PetType(SQLAlchemyObjectType): class Meta: model = Pet interfaces = (relay.Node,) batching = True class Query(graphene.ObjectType): articles = graphene.Field(graphene.List(ArticleType)) reporters = graphene.Field(graphene.List(ReporterType)) def resolve_articles(self, info): return info.context.get('session').query(Article).all() def resolve_reporters(self, info): return info.context.get('session').query(Reporter).all() return graphene.Schema(query=Query)
Example #13
Source File: test_converter.py From graphene-sqlalchemy with MIT License | 5 votes |
def test_should_onetoone_convert_field(): class A(SQLAlchemyObjectType): class Meta: model = Article interfaces = (Node,) dynamic_field = convert_sqlalchemy_relationship( Reporter.favorite_article.property, A, default_connection_field_factory, True, 'orm_field_name', ) assert isinstance(dynamic_field, graphene.Dynamic) graphene_type = dynamic_field.get_type() assert isinstance(graphene_type, graphene.Field) assert graphene_type.type == A
Example #14
Source File: test_converter.py From graphene-sqlalchemy with MIT License | 5 votes |
def test_should_manytoone_convert_connectionorlist_connection(): class A(SQLAlchemyObjectType): class Meta: model = Reporter interfaces = (Node,) dynamic_field = convert_sqlalchemy_relationship( Article.reporter.property, A, default_connection_field_factory, True, 'orm_field_name', ) assert isinstance(dynamic_field, graphene.Dynamic) graphene_type = dynamic_field.get_type() assert isinstance(graphene_type, graphene.Field) assert graphene_type.type == A
Example #15
Source File: test_converter.py From graphene-sqlalchemy with MIT License | 5 votes |
def test_should_manytomany_convert_connectionorlist_connection(): class A(SQLAlchemyObjectType): class Meta: model = Pet interfaces = (Node,) dynamic_field = convert_sqlalchemy_relationship( Reporter.pets.property, A, default_connection_field_factory, True, 'orm_field_name', ) assert isinstance(dynamic_field, graphene.Dynamic) assert isinstance(dynamic_field.get_type(), UnsortedSQLAlchemyConnectionField)
Example #16
Source File: test_benchmark.py From graphene-sqlalchemy with MIT License | 5 votes |
def get_schema(): class ReporterType(SQLAlchemyObjectType): class Meta: model = Reporter interfaces = (relay.Node,) connection_field_factory = BatchSQLAlchemyConnectionField.from_relationship class ArticleType(SQLAlchemyObjectType): class Meta: model = Article interfaces = (relay.Node,) connection_field_factory = BatchSQLAlchemyConnectionField.from_relationship class PetType(SQLAlchemyObjectType): class Meta: model = Pet interfaces = (relay.Node,) connection_field_factory = BatchSQLAlchemyConnectionField.from_relationship class Query(graphene.ObjectType): articles = graphene.Field(graphene.List(ArticleType)) reporters = graphene.Field(graphene.List(ReporterType)) def resolve_articles(self, info): return info.context.get('session').query(Article).all() def resolve_reporters(self, info): return info.context.get('session').query(Reporter).all() return graphene.Schema(query=Query)
Example #17
Source File: test_converter.py From graphql-pynamodb with MIT License | 5 votes |
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)
Example #18
Source File: test_converter.py From graphql-pynamodb with MIT License | 5 votes |
def test_should_onetoone_convert_field(): class A(PynamoObjectType): class Meta: model = Article interfaces = [relay.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
Example #19
Source File: test_fields.py From graphene-django with MIT License | 4 votes |
def test_integer_field_filter_type(): class PetType(DjangoObjectType): class Meta: model = Pet interfaces = (Node,) filter_fields = {"age": ["exact"]} fields = ("age",) class Query(ObjectType): pets = DjangoFilterConnectionField(PetType) schema = Schema(query=Query) assert str(schema) == dedent( """\ schema { query: Query } interface Node { id: ID! } type PageInfo { hasNextPage: Boolean! hasPreviousPage: Boolean! startCursor: String endCursor: String } type PetType implements Node { age: Int! id: ID! } type PetTypeConnection { pageInfo: PageInfo! edges: [PetTypeEdge]! } type PetTypeEdge { node: PetType cursor: String! } type Query { pets(before: String, after: String, first: Int, last: Int, age: Int): PetTypeConnection } """ )
Example #20
Source File: types.py From graphene-gae with BSD 3-Clause "New" or "Revised" License | 4 votes |
def __init_subclass_with_meta__(cls, model=None, registry=None, skip_registry=False, only_fields=(), exclude_fields=(), connection=None, use_connection=None, interfaces=(), **options): if not model: raise Exception(( 'NdbObjectType {name} must have a model in the Meta class attr' ).format(name=cls.__name__)) if not inspect.isclass(model) or not issubclass(model, ndb.Model): raise Exception(( 'Provided model in {name} is not an NDB model' ).format(name=cls.__name__)) if not registry: registry = get_global_registry() assert isinstance(registry, Registry), ( 'The attribute registry in {} needs to be an instance of ' 'Registry, received "{}".' ).format(cls.__name__, registry) ndb_fields = fields_for_ndb_model(model, registry, only_fields, exclude_fields) ndb_fields = yank_fields_from_attrs( ndb_fields, _as=Field, ) if use_connection is None and interfaces: use_connection = any((issubclass(interface, Node) for interface in interfaces)) if use_connection and not connection: # We create the connection automatically connection = Connection.create_type('{}Connection'.format(cls.__name__), node=cls) if connection is not None: assert issubclass(connection, Connection), ( "The connection must be a Connection. Received {}" ).format(connection.__name__) _meta = NdbObjectTypeOptions(cls) _meta.model = model _meta.registry = registry _meta.fields = ndb_fields _meta.connection = connection super(NdbObjectType, cls).__init_subclass_with_meta__(_meta=_meta, interfaces=interfaces, **options) if not skip_registry: registry.register(cls)
Example #21
Source File: test_fields.py From graphene-django with MIT License | 4 votes |
def test_annotation_is_preserved(): class ReporterType(DjangoObjectType): full_name = String() def resolve_full_name(instance, info, **args): return instance.full_name class Meta: model = Reporter interfaces = (Node,) filter_fields = () class Query(ObjectType): all_reporters = DjangoFilterConnectionField(ReporterType) def resolve_all_reporters(self, info, **args): return Reporter.objects.annotate( full_name=Concat( "first_name", Value(" "), "last_name", output_field=TextField() ) ) Reporter.objects.create(first_name="John", last_name="Doe") schema = Schema(query=Query) query = """ query NodeFilteringQuery { allReporters(first: 1) { edges { node { fullName } } } } """ expected = {"allReporters": {"edges": [{"node": {"fullName": "John Doe"}}]}} result = schema.execute(query) assert not result.errors assert result.data == expected
Example #22
Source File: test_fields.py From graphene-django with MIT License | 4 votes |
def test_order_by_is_perserved(): class ReporterType(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) filter_fields = () class Query(ObjectType): all_reporters = DjangoFilterConnectionField( ReporterType, reverse_order=Boolean() ) def resolve_all_reporters(self, info, reverse_order=False, **args): reporters = Reporter.objects.order_by("first_name") if reverse_order: return reporters.reverse() return reporters Reporter.objects.create(first_name="b") Reporter.objects.create(first_name="a") schema = Schema(query=Query) query = """ query NodeFilteringQuery { allReporters(first: 1) { edges { node { firstName } } } } """ expected = {"allReporters": {"edges": [{"node": {"firstName": "a"}}]}} result = schema.execute(query) assert not result.errors assert result.data == expected reverse_query = """ query NodeFilteringQuery { allReporters(first: 1, reverseOrder: true) { edges { node { firstName } } } } """ reverse_expected = {"allReporters": {"edges": [{"node": {"firstName": "b"}}]}} reverse_result = schema.execute(reverse_query) assert not reverse_result.errors assert reverse_result.data == reverse_expected
Example #23
Source File: test_fields.py From graphene-django with MIT License | 4 votes |
def test_other_filter_types(): class PetType(DjangoObjectType): class Meta: model = Pet interfaces = (Node,) filter_fields = {"age": ["exact", "isnull", "lt"]} fields = ("age",) class Query(ObjectType): pets = DjangoFilterConnectionField(PetType) schema = Schema(query=Query) assert str(schema) == dedent( """\ schema { query: Query } interface Node { id: ID! } type PageInfo { hasNextPage: Boolean! hasPreviousPage: Boolean! startCursor: String endCursor: String } type PetType implements Node { age: Int! id: ID! } type PetTypeConnection { pageInfo: PageInfo! edges: [PetTypeEdge]! } type PetTypeEdge { node: PetType cursor: String! } type Query { pets(before: String, after: String, first: Int, last: Int, age: Int, age_Isnull: Boolean, age_Lt: Int): PetTypeConnection } """ )
Example #24
Source File: test_fields.py From graphene-django with MIT License | 4 votes |
def test_global_id_field_relation_with_filter(): class ReporterFilterNode(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) filter_fields = ["first_name", "articles"] class ArticleFilterNode(DjangoObjectType): class Meta: model = Article interfaces = (Node,) filter_fields = ["headline", "reporter"] class Query(ObjectType): all_reporters = DjangoFilterConnectionField(ReporterFilterNode) all_articles = DjangoFilterConnectionField(ArticleFilterNode) reporter = Field(ReporterFilterNode) article = Field(ArticleFilterNode) r1 = Reporter.objects.create(first_name="r1", last_name="r1", email="r1@test.com") r2 = Reporter.objects.create(first_name="r2", last_name="r2", email="r2@test.com") Article.objects.create( headline="a1", pub_date=datetime.now(), pub_date_time=datetime.now(), reporter=r1, editor=r1, ) Article.objects.create( headline="a2", pub_date=datetime.now(), pub_date_time=datetime.now(), reporter=r2, editor=r2, ) # Query articles created by the reporter `r1` query = """ query { allArticles (reporter: "UmVwb3J0ZXJGaWx0ZXJOb2RlOjE=") { edges { node { id } } } } """ schema = Schema(query=Query) result = schema.execute(query) assert not result.errors # We should only get back a single article assert len(result.data["allArticles"]["edges"]) == 1
Example #25
Source File: test_query.py From graphene-django with MIT License | 4 votes |
def test_should_query_connectionfilter(graphene_settings, max_limit): graphene_settings.RELAY_CONNECTION_MAX_LIMIT = max_limit from ...filter import DjangoFilterConnectionField r1 = Reporter(last_name="ABA") r1.save() r2 = Reporter(last_name="Griffin") r2.save() class ReporterType(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) class Query(graphene.ObjectType): all_reporters = DjangoFilterConnectionField(ReporterType, fields=["last_name"]) s = graphene.String(resolver=lambda *_: "S") debug = graphene.Field(DjangoDebug, name="__debug") def resolve_all_reporters(self, info, **args): return Reporter.objects.all() query = """ query ReporterQuery { allReporters(first:1) { edges { node { lastName } } } __debug { sql { rawSql } } } """ expected = {"allReporters": {"edges": [{"node": {"lastName": "ABA"}}]}} schema = graphene.Schema(query=Query) result = schema.execute( query, context_value=context(), middleware=[DjangoDebugMiddleware()] ) assert not result.errors assert result.data["allReporters"] == expected["allReporters"] assert len(result.data["__debug"]["sql"]) == 2 assert "COUNT" in result.data["__debug"]["sql"][0]["rawSql"] query = str(Reporter.objects.all()[:1].query) assert result.data["__debug"]["sql"][1]["rawSql"] == query
Example #26
Source File: test_query.py From graphene-django with MIT License | 4 votes |
def test_should_query_connection(graphene_settings, max_limit): graphene_settings.RELAY_CONNECTION_MAX_LIMIT = max_limit r1 = Reporter(last_name="ABA") r1.save() r2 = Reporter(last_name="Griffin") r2.save() class ReporterType(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) class Query(graphene.ObjectType): all_reporters = DjangoConnectionField(ReporterType) debug = graphene.Field(DjangoDebug, name="__debug") def resolve_all_reporters(self, info, **args): return Reporter.objects.all() query = """ query ReporterQuery { allReporters(first:1) { edges { node { lastName } } } __debug { sql { rawSql } } } """ expected = {"allReporters": {"edges": [{"node": {"lastName": "ABA"}}]}} schema = graphene.Schema(query=Query) result = schema.execute( query, context_value=context(), middleware=[DjangoDebugMiddleware()] ) assert not result.errors assert result.data["allReporters"] == expected["allReporters"] assert len(result.data["__debug"]["sql"]) == 2 assert "COUNT" in result.data["__debug"]["sql"][0]["rawSql"] query = str(Reporter.objects.all()[:1].query) assert result.data["__debug"]["sql"][1]["rawSql"] == query
Example #27
Source File: test_query.py From graphene-django with MIT License | 4 votes |
def test_should_query_field(): r1 = Reporter(last_name="ABA") r1.save() r2 = Reporter(last_name="Griffin") r2.save() class ReporterType(DjangoObjectType): class Meta: model = Reporter interfaces = (Node,) class Query(graphene.ObjectType): reporter = graphene.Field(ReporterType) debug = graphene.Field(DjangoDebug, name="__debug") def resolve_reporter(self, info, **args): return Reporter.objects.first() query = """ query ReporterQuery { reporter { lastName } __debug { sql { rawSql } } } """ expected = { "reporter": {"lastName": "ABA"}, "__debug": { "sql": [{"rawSql": str(Reporter.objects.order_by("pk")[:1].query)}] }, } schema = graphene.Schema(query=Query) result = schema.execute( query, context_value=context(), middleware=[DjangoDebugMiddleware()] ) assert not result.errors assert result.data == expected
Example #28
Source File: test_batching.py From graphene-sqlalchemy with MIT License | 4 votes |
def test_connection_factory_field_overrides_batching_is_true(session_factory): session = session_factory() reporter_1 = Reporter(first_name='Reporter_1') session.add(reporter_1) reporter_2 = Reporter(first_name='Reporter_2') session.add(reporter_2) session.commit() session.close() class ReporterType(SQLAlchemyObjectType): class Meta: model = Reporter interfaces = (relay.Node,) batching = True connection_field_factory = default_connection_field_factory articles = ORMField(batching=True) class ArticleType(SQLAlchemyObjectType): class Meta: model = Article interfaces = (relay.Node,) class Query(graphene.ObjectType): reporters = graphene.Field(graphene.List(ReporterType)) def resolve_reporters(self, info): return info.context.get('session').query(Reporter).all() schema = graphene.Schema(query=Query) with mock_sqlalchemy_logging_handler() as sqlalchemy_logging_handler: # Starts new session to fully reset the engine / connection logging level session = session_factory() schema.execute(""" query { reporters { articles { edges { node { headline } } } } } """, context_value={"session": session}) messages = sqlalchemy_logging_handler.messages select_statements = [message for message in messages if 'SELECT' in message and 'FROM articles' in message] assert len(select_statements) == 2